添加触摸国与jQuery
问题描述:
http://jsfiddle.net/JamesKyle/Ke536/添加触摸国与jQuery
正如你可以看到我做了与hover
和active
类,我试图找到添加简单的触摸事件到页面上的所有元素的简单方法。
$(document).ready(function() {
// MOUSE
$('*').mouseover(function() {$(this).addClass('hover');});
$('*').mouseout(function() {$('.hover').removeClass('hover');});
$('*').mousedown(function() {$(this).addClass('active');});
$('*').mouseup(function() {$('.active').removeClass('active');});
// TOUCH
// On touch down wait (100ms) > add class touch
// On touch move > remove class touch
// On touch up > add class active
});
我希望这是添加类触摸之前稍有延迟,这样,当用户实际上滚动这就是为什么我也想删除触摸移动类它不会触发。
你可以在这里看到的jsfiddle: http://jsfiddle.net/JamesKyle/Ke536/
答
看看各个事件touchstart
,touchmove
和touchend
。
您可以以编程方式确定使用与+new Date
的增量所用的时间。