我正在使用这段很棒的代码来模拟 Android 上的触摸事件 http://pervasivecode.blogspot.co.nz/2011/11/android-phonegap-active-css-pseudo.html .效果很好,但太敏感了。例如,如果您有一个列表并且想要在您触摸列表中任何作为它突出显示的链接的内容时向下滚动。
$(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");
});
}
});
是否可以延迟类(class)变更,或者我可以使用其他触发器吗?
最佳答案
为避免在滚动时激活链接,您可以使用 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;
});
}
关于jquery - touchstart太敏感,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9375130/