2011-12-23 58 views
0

我有一系列的列表項。在iPhone(觸控設備)上,當用戶在屏幕上觸摸並移動他的手指時,我想要捕捉他觸摸的所有元素。如何檢測touchmove上的html元素

那麼我該如何得到它呢?假設我想獲得這些元素的所有ID,並在觸摸結束時發出警報。

我試圖用jQuery Mobile的以「刷」事件,但只有第一個被感動,太如果‘觸摸’開始從特定的元素出現。

回答

1

不知道這是否會在工作移動設備,除非你禁用滾動。

工程桌面和還挺我的iPhone

JS

// List of events: http://api.jquery.com/category/events/ 
// tap taphold swipe swiperight swipeleft 
// click change dblclick submit 
function bindEvents(element) { 
    element.bind('mouseenter', function(event) { 
     //alert('Element Id: '+$(element).attr('id')+' Event: '+event.type); 
     console.log('Element Id: '+$(element).attr('id')+' Event: '+event.type); 
    }); 
} 

$('#theList li').each(function(){ 
    bindEvents($(this)); 
}); 

HTML

<div data-role="page" class="type-home"> 
    <div data-role="content"> 

     <ul id="theList" data-role="listview" data-inset="true" data-theme="c" data-dividertheme="f"> 
      <li id="list-d" data-role="list-divider">Items</li> 
      <li id="list-item-1"><a href="#">List Item 1</a></li> 
      <li id="list-item-2"><a href="#">List Item 2</a></li> 
      <li id="list-item-3"><a href="#">List Item 3</a></li> 
      <li id="list-item-4"><a href="#">List Item 4</a></li> 
      <li id="list-item-5"><a href="#">List Item 5</a></li> 
      <li id="list-item-6"><a href="#">List Item 6</a></li> 
      <li id="list-item-7"><a href="#">List Item 7</a></li> 
      <li id="list-item-8"><a href="#">List Item 8</a></li> 
      <li id="list-item-9"><a href="#">List Item 9</a></li> 
      <li id="list-item-10"><a href="#">List Item 10</a></li> 
     </ul> 

    </div> 
</div> 

我敢肯定,你可以綁定多個事件和日誌他們找到你正在尋找正確的組合。