觸摸事件在用戶觸摸屏幕(頁面)時觸發(fā)。
![]() |
觸摸事件同樣可應用與桌面電腦上:點擊或者滑動鼠標! |
---|
jQuery Mobile 點擊
點擊事件在用戶點擊元素時觸發(fā)。
如下實例:當點擊 <p> 元素時,隱藏當前的 <p> 元素:
實例
<!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="http://apps.bdimg.com/libs/jquerymobile/1.4.5/jquery.mobile-1.4.5.min.css"> <script src="http://apps.bdimg.com/libs/jquery/1.10.2/jquery.min.js"></script> <script src="http://apps.bdimg.com/libs/jquerymobile/1.4.5/jquery.mobile-1.4.5.min.js"></script> <script> $(document).on("pagecreate","#pageone",function(){ $("p").on("tap",function(){ $(this).hide(); }); }); </script> </head> <body> <div data-role="page" id="pageone"> <div data-role="header"> <h1>tap 事件</h1> </div> <div data-role="main" class="ui-content"> <p>敲擊我,我會消失。</p> <p>敲擊我,我會消失。</p> <p>敲擊我,我也會消失。</p> </div> <div data-role="footer"> <h1>頁腳文本</h1> </div> </div> </body> </html>
運行實例 ?
點擊 "運行實例" 按鈕查看在線實例
jQuery Mobile 點擊不放(長按)
點擊不放(長按) 事件在點擊并不放(大約一秒)后觸發(fā)
實例
<!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="http://apps.bdimg.com/libs/jquerymobile/1.4.5/jquery.mobile-1.4.5.min.css"> <script src="http://apps.bdimg.com/libs/jquery/1.10.2/jquery.min.js"></script> <script src="http://apps.bdimg.com/libs/jquerymobile/1.4.5/jquery.mobile-1.4.5.min.js"></script> <script> $(document).on("pagecreate","#pageone",function(){ $("p").on("taphold",function(){ $(this).hide(); }); }); </script> </head> <body> <div data-role="page" id="pageone"> <div data-role="header"> <h1>taphold 事件</h1> </div> <div data-role="main" class="ui-content"> <p>如果您敲擊并保持一秒鐘,我會消失。</p> <p>敲擊并保持住,我會消失。</p> <p>敲擊并保持住,我也會消失。</p> </div> <div data-role="footer"> <h1>頁腳文本</h1> </div> </div> </body> </html>
運行實例 ?
點擊 "運行實例" 按鈕查看在線實例
jQuery Mobile 滑動
滑動事件是在用戶一秒內水平拖拽大于30PX,或者縱向拖曳小于20px的事件發(fā)生時觸發(fā)的事件:
實例
<!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="http://apps.bdimg.com/libs/jquerymobile/1.4.5/jquery.mobile-1.4.5.min.css"> <script src="http://apps.bdimg.com/libs/jquery/1.10.2/jquery.min.js"></script> <script src="http://apps.bdimg.com/libs/jquerymobile/1.4.5/jquery.mobile-1.4.5.min.js"></script> <script> $(document).on("pagecreate","#pageone",function(){ $("p").on("swipe",function(){ $("span").text("滑動檢測!"); }); }); </script> </head> <body> <div data-role="page" id="pageone"> <div data-role="header"> <h1>swipe 事件</h1> </div> <div data-role="main" class="ui-content"> <p>在下面的文本或方框上滑動。</p> <p style="border:1px solid black;height:200px;width:200px;"></p> <p><span style="color:red"></span></p> </div> <div data-role="footer"> <h1>頁腳文本</h1> </div> </div> </body> </html>
運行實例 ?
點擊 "運行實例" 按鈕查看在線實例
jQuery Mobile 向左滑動
向左滑動事件在用戶向左拖動元素大于30px時觸發(fā):
實例
<!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="http://apps.bdimg.com/libs/jquerymobile/1.4.5/jquery.mobile-1.4.5.min.css"> <script src="http://apps.bdimg.com/libs/jquery/1.10.2/jquery.min.js"></script> <script src="http://apps.bdimg.com/libs/jquerymobile/1.4.5/jquery.mobile-1.4.5.min.js"></script> <script> $(document).on("pagecreate","#pageone",function(){ $("p").on("swipeleft",function(){ alert("您向左滑動!"); }); }); </script> </head> <body> <div data-role="page" id="pageone"> <div data-role="header"> <h1>swipeleft 事件</h1> </div> <div data-role="main" class="ui-content"> <p style="border:1px solid black;margin:5px;">向左滑動 - 不要超出邊框!</p> </div> <div data-role="footer"> <h1>頁腳文本</h1> </div> </div> </body> </html>
運行實例 ?
點擊 "運行實例" 按鈕查看在線實例
jQuery Mobile 向右滑動
向右滑動事件在用戶向右拖動元素大于30px時觸發(fā):
實例
<!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="http://apps.bdimg.com/libs/jquerymobile/1.4.5/jquery.mobile-1.4.5.min.css"> <script src="http://apps.bdimg.com/libs/jquery/1.10.2/jquery.min.js"></script> <script src="http://apps.bdimg.com/libs/jquerymobile/1.4.5/jquery.mobile-1.4.5.min.js"></script> <script> $(document).on("pagecreate","#pageone",function(){ $("p").on("swiperight",function(){ alert("向右滑動!"); }); }); </script> </head> <body> <div data-role="page" id="pageone"> <div data-role="header"> <h1>swiperight 事件</h1> </div> <div data-role="main" class="ui-content"> <p style="border:1px solid black;margin:5px;">向右滑動 - 不要超出邊框!</p> </div> <div data-role="footer"> <h1>頁腳文本</h1> </div> </div> </body> </html>
運行實例 ?
點擊 "運行實例" 按鈕查看在線實例