微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

javascript – jQuery mouseleave的触摸屏/平板电脑

我有一个模式盒子,在鼠标器上褪色,并在老鼠眼上淡出.唯一的问题是使用触摸屏设备(如平板电脑)时,一旦显示页面上,就无法获得模式淡出.有没有办法将此代码修改到任何时候用户在模式框外触摸会淡出的地方?
$(".tiptrigger").mouseenter(function() { 

    var s_id = $(this).attr('id'); // There may be more than one per page
    $("#tiptip_holder-"+s_id).fadeIn("fast");   

}); 

$(".tiptrigger").mouseleave(function() { 

    var s_id = $(this).attr('id');
    $("#tiptip_holder-"+s_id).fadeOut("slow");

});

解决方法

您可以尝试使用触摸事件(未测试):
$('.tiptrigger').on('mouseenter touchstart',function(){ 
    var s_id = $(this).attr('id'); // There may be more than one per page
    $("#tiptip_holder-"+s_id).fadeIn("fast"); 
});

$('.tiptrigger').on('mouseleave touchend',function(){
    var s_id = $(this).attr('id');
    $("#tiptip_holder-"+s_id).fadeOut("slow");
});

编辑

你可以试试:

$('.tiptrigger').on('mouseenter touchstart',function(e){ 
    var s_id = $(this).attr('id'); // There may be more than one per page
    $("#tiptip_holder-"+s_id).fadeIn("fast"); 
    e.stopPropagation()
});

$('.tiptrigger').on('mouseleave',function(e){
    var s_id = $(this).attr('id');
    $("#tiptip_holder-"+s_id).fadeOut("slow");
});

$('body').on('touchstart',function(e){ 
    $("div[id^='tiptip_holder']").fadeOut("slow");        
});

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐