2011-11-30 102 views
0

http://jsfiddle.net/JamesKyle/Ke536/添加觸摸國與jQuery

正如你可以看到我做了與hoveractive類,我試圖找到添加簡單的觸摸事件到頁面上的所有元素的簡單方法。

$(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/

回答

0

看看各個事件touchstarttouchmovetouchend

您可以以編程方式確定使用與+new Date的增量所用的時間。