2012-02-21 113 views
3

我使用这个非常棒的代码来模拟Android http://pervasivecode.blogspot.co.nz/2011/11/android-phonegap-active-css-pseudo.html上的触摸事件。工程很好,但太敏感。例如,如果你有一个列表,并且当你触摸列表上的任何东西,它就会突出显示一个链接。touchstart太敏感了

$(document).ready(function(){ 
if (navigator.userAgent.toLowerCase().indexOf("android") > -1) { 
$('a') 
.bind("touchstart", function() { 
    $(this).addClass("fake-active"); 

     }) 
.bind("touchend", function() { 
    $(this).removeClass("fake-active"); 
    }); 
} 
    }); 

是否有可能延迟班级更改或是否存在可以使用的另一个触发器?

回答

1

为了避免在滚动时激活链接,可以使用touchend触发类更改,并检查滚动(如果存在)。像这样的东西...

if (navigator.userAgent.toLowerCase().indexOf("android") > -1){ 

    var scroll = 0; 
    $('a').on("touchstart",function(){ 
     $('a').removeClass("fake-active"); 
    }).on("touchend",function(){ 
     if(scroll == 0){ 
      $(this).addClass("fake-active"); 
     } 
     scroll = 0; //Ideally should be set when scrolling is finished 
    }); 

    $('ELEMENT-THAT-IS-SCROLLING').scroll(function(){ 
    scroll = 1; 
    }); 

}