在iPhone中,实现tap淡出效果

在iPhone中,实现tap淡出效果

问题描述:

jQuery代码:

setTips: function() {
            $(".tooltip").parent().hover(function(){

            TT.current = $(this);
            TT.timer = setTimeout(function(){
            TT.current.find(".tooltip").fadeIn('fast');
                }, TT.delay);
            }, function(){
                clearTimeout(TT.timer);
                $(this).find(".tooltip").fadeOut('fast');

在浏览器可以正常运行,但是移植到iPhone上之后,显示工具提示后它不能隐藏了。
有没有什么方法能让tap隐藏实现淡出效果?

可以给tap上的工具提示添加一个click事件来隐藏:

$('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');
});

补充:

问题可能是iPhone悬停引起的,所以我建议无触屏绑定悬停,触屏绑定点击,

用jsFiddle,http://jsfiddle.net/RAJ5Q/1/

if ( $('html').hasClass('no-touch') ) {
    // 绑定到悬停事件
}
else {
    // 点击事件
}