jQuery Mobile touch events
Touch events are triggered when the user touches the screen (page).
Touch events can also be applied to desktop computers: Click or slide the mouse! |
jQuery Mobile Click
Click events are fired when the user clicks on an element.
The following example: when the <p> element is clicked, the current <p> element is hidden:
Example
<!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>
Running instance »
Click the "Run Instance" button to view the online instance
jQuery Mobile click and hold (long press)
Click and hold (long press) event is triggered after clicking and holding (about one second)
Example
<!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>
Running instance »
Click the "Run Instance" button to view the online instance
jQuery Mobile Slide
The sliding event is an event triggered when the user drags horizontally more than 30px or vertically less than 20px within one second:
Example
<!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>
Running instance »
Click the "Run Instance" button to view the online instance
jQuery Mobile Swipe left
The slide left event is triggered when the user drags an element to the left greater than 30px:
Example
<!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>
Running instance »
Click the "Run Instance" button to view the online instance
jQuery Mobile Swipe right
The slide right event is triggered when the user drags an element to the right greater than 30px:
Example
<!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>
Running instance »
Click the "Run Instance" button to view the online instance