2012-05-31 119 views
1

請別人幫我這個:HTML5部分touchstart touchmove touchend的iOS

touchStart = function (evt) { 
     evt.preventDefault(); 
     $(this).addClass("touched"); 
    }; 

    touchEnd = function (evt) { 
     evt.preventDefault(); 
     $(this).removeClass("touched"); 
    }; 

    s.ontouchstart = touchStart; 
    s.ontouchend = touchEnd; 
    s.ontouchmove = touchEnd; 

我有一節元素,由JavaScript(ul> li>章節)動態生成。當我將touchstart-touchmove-touchend事件監聽器綁定到此部分元素時,它適用於Android,但不適用於iPad/iPod/iPhone。

我試過用onclick="void(0)"屬性來生成它,它使得section元素「interact」像一個可點擊的元素,但它仍然沒有任何作用。

,每天的方式適用於Android,但這種蔬菜似乎有點消耗對我沒用,現在... =)提前

謝謝! =)

回答

4

沒關係,把它與jQuery。這種方式無處不在。

$(s).bind("touchstart mousedown", function (e) { 
    console.log(e.type); // to get the name of the event 
}).bind("touchmove mousemove", function (e) { 
    // ... 
}).bind("touchend mouseup", function (e) { 
    // ... 
}); 
+0

該代碼將在支持觸摸的瀏覽器中觸發兩次。檢查出來:$(document).ready(function(){('body')。bind(「touchstart mousedown」,function(e){ console.log(「test」+ Date.now()) ; }); }); – fisherwebdev

+0

yupp,最終溶液處理它=) – benqus

+0

似乎沒有爲$工作( '滑塊UL利')。結合( 「鼠標按下touchstart」,函數(E){ \t \t \t \t的console.log(e.type ); //獲取事件 \t \t \t \t})的名稱綁定( 「鼠標移動touchmove」,函數(E){ \t \t \t \t的console.log(e.type); \t \t \t \t })。bind(「touchend mouseup」,function(e){ \t \t \t \t console.log(e.type); \t \t \t \t}); – Sarvesh

相關問題