Jquery 在iPhone上,轻按“外侧范围”将其淡出

Jquery 在iPhone上,轻按“外侧范围”将其淡出,jquery,iphone,tooltip,Jquery,Iphone,Tooltip,我有以下jQuery代码 setTips: function() { $(".tooltip").parent().hover(function(){ //store the tooltip being hovered TT.current = $(this); TT.timer = setTimeout(function(){ //find the tooltip

我有以下jQuery代码

 setTips: function() {
            $(".tooltip").parent().hover(function(){
            //store the tooltip being hovered
            TT.current = $(this);
            TT.timer = setTimeout(function(){
                //find the tooltip
                TT.current.find(".tooltip").fadeIn('fast');
                }, TT.delay);
            }, function(){
                //on mouseout, clear timer and hide tooltip
                clearTimeout(TT.timer);
                $(this).find(".tooltip").fadeOut('fast');
它在浏览器上运行良好,但在iphone上,无论何时出现工具提示,都无法隐藏它


有没有一种方法可以点击跨度外的部分并使其淡出?谢谢大家!

在任何点击时隐藏工具提示的一般点击事件如何,如下图所示

$('body').on('click', function(e) {
    if ( $(e.target).hasClass('.element-that-called-tooltip') ) return; // return if the tapped element was one that called the tooltip
    $('.tooltip').fadeOut('fast');
});
编辑:

所以问题在于iOS悬停事件。我认为缓解这种情况的最好方法是使用功能检测(类似于库),为非触摸设备绑定悬停事件,为触摸设备绑定单击事件

jsFiddle:


隐藏工具提示效果很好,但是,如果我尝试单击返回工具提示的元素,它将不再显示。它保持隐藏。您是否修改了函数的第一行(特别是类选择器)以返回单击的元素是否触发工具提示?不,我没有,我只是包含了您给我的代码,该代码实际上在浏览器上运行得非常好。单击标记后,它将淡出,当鼠标移回上方时,工具提示将淡入。然而,在iPhone上,它在关闭后不会回来。嗯,很难说发生了什么。不过,这可能有点棘手,当涉及javascript时,iOS的“悬停点击”实现实际上会导致问题。也许如果你做了一个游戏,我们可以玩它?问题是,正如我所怀疑的,iOS不想注册“悬停点击”事件,因为它认为元素仍然在焦点中。尝试点击编辑器的另一个部分,然后返回结果并点击文本,它会再次返回。最好检测设备的类型,然后根据该类型设置工具提示。我会给你一个tic的演示。
if ( $('html').hasClass('no-touch') ) {
    // bind to hover
}
else {
    // bind to click
}