tutorial-Tap_vs_swipe.html 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>Tutorial: Tap vs swipe - Documentation</title>
  6. <script src="scripts/prettify/prettify.js"></script>
  7. <script src="scripts/prettify/lang-css.js"></script>
  8. <!--[if lt IE 9]>
  9. <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
  10. <![endif]-->
  11. <link type="text/css" rel="stylesheet" href="https://code.ionicframework.com/ionicons/2.0.1/css/ionicons.min.css">
  12. <link type="text/css" rel="stylesheet" href="styles/prettify.css">
  13. <link type="text/css" rel="stylesheet" href="styles/jsdoc.css">
  14. </head>
  15. <body>
  16. <input type="checkbox" id="nav-trigger" class="nav-trigger" />
  17. <label for="nav-trigger" class="navicon-button x">
  18. <div class="navicon"></div>
  19. </label>
  20. <label for="nav-trigger" class="overlay"></label>
  21. <nav>
  22. <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="$.html">$</a></li><li><a href="$.fn.html">fn</a></li><li><a href="$.fn.swipe.html">swipe</a><ul class='methods'><li data-type='method'><a href="$.fn.swipe.html#destroy">destroy</a></li><li data-type='method'><a href="$.fn.swipe.html#disable">disable</a></li><li data-type='method'><a href="$.fn.swipe.html#enable">enable</a></li><li data-type='method'><a href="$.fn.swipe.html#option">option</a></li></ul></li></ul><h3>Events</h3><ul><li><a href="$.fn.swipe.html#event:click">click</a></li><li><a href="$.fn.swipe.html#event:doubleTap">doubleTap</a></li><li><a href="$.fn.swipe.html#event:hold">hold</a></li><li><a href="$.fn.swipe.html#event:longTap">longTap</a></li><li><a href="$.fn.swipe.html#event:pinchIn">pinchIn</a></li><li><a href="$.fn.swipe.html#event:pinchOut">pinchOut</a></li><li><a href="$.fn.swipe.html#event:pinchStatus">pinchStatus</a></li><li><a href="$.fn.swipe.html#event:swipe">swipe</a></li><li><a href="$.fn.swipe.html#event:swipeDown">swipeDown</a></li><li><a href="$.fn.swipe.html#event:swipeLeft">swipeLeft</a></li><li><a href="$.fn.swipe.html#event:swipeRight">swipeRight</a></li><li><a href="$.fn.swipe.html#event:swipeStatus">swipeStatus</a></li><li><a href="$.fn.swipe.html#event:swipeUp">swipeUp</a></li><li><a href="$.fn.swipe.html#event:tap">tap</a></li></ul><h3>Namespaces</h3><ul><li><a href="$.fn.swipe.defaults.html">defaults</a></li><li><a href="$.fn.swipe.directions.html">directions</a></li><li><a href="$.fn.swipe.fingers.html">fingers</a></li><li><a href="$.fn.swipe.pageScroll.html">pageScroll</a></li><li><a href="$.fn.swipe.phases.html">phases</a></li></ul><h3>Tutorials</h3><ul><li><a href="tutorial-Any_finger_swipe.html">Any finger swipe</a></li><li><a href="tutorial-Basic_swipe.html">Basic swipe</a></li><li><a href="tutorial-Enable_and_destroy.html">Enable and destroy</a></li><li><a href="tutorial-Excluded_children.html">Excluded children</a></li><li><a href="tutorial-Finger_swipe.html">Finger swipe</a></li><li><a href="tutorial-Handlers_and_events.html">Handlers and events</a></li><li><a href="tutorial-Hold.html">Hold</a></li><li><a href="tutorial-Image_gallery_example.html">Image gallery example</a></li><li><a href="tutorial-Options.html">Options</a></li><li><a href="tutorial-Page_scrolling.html">Page scrolling</a></li><li><a href="tutorial-Page_zoom.html">Page zoom</a></li><li><a href="tutorial-Pinch.html">Pinch</a></li><li><a href="tutorial-Pinch_and_Swipe.html">Pinch and Swipe</a></li><li><a href="tutorial-Pinch_status.html">Pinch status</a></li><li><a href="tutorial-Single_swipe.html">Single swipe</a></li><li><a href="tutorial-Stop_propegation.html">Stop_propegation</a></li><li><a href="tutorial-Swipe_status.html">Swipe status</a></li><li><a href="tutorial-Tap_vs_swipe.html">Tap vs swipe</a></li><li><a href="tutorial-Thresholds.html">Thresholds</a></li><li><a href="tutorial-Trigger_handlers.html">Trigger handlers</a></li><li><a href="tutorial-index_.html">index</a></li></ul>
  23. </nav>
  24. <div id="main">
  25. <h1 class="page-title">Tutorial: Tap vs swipe</h1>
  26. <section>
  27. <header>
  28. <h2>Tap vs swipe</h2>
  29. </header>
  30. <article>
  31. <!DOCTYPE HTML>
  32. <html>
  33. <head>
  34. <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
  35. <meta http-equiv="x-ua-compatible" content="IE=9">
  36. <link href="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.2.2/css/bootstrap-combined.min.css" rel="stylesheet">
  37. <link href="http://twitter.github.com/bootstrap/assets/js/google-code-prettify/prettify.css" rel="stylesheet" />
  38. <link href="css/main.css" type="text/css" rel="stylesheet" />
  39. <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
  40. <script type="text/javascript" src="https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js"></script>
  41. <script type="text/javascript" src="../jquery.touchSwipe.js"></script>
  42. <script type="text/javascript" src="js/main.js"></script>
  43. <!-- use the jquery.ui.ipad.js plugin to translate touch events to mouse events -->
  44. <script type="text/javascript" src="js/jquery.ui.ipad.js"></script>
  45. <title>touchSwipe</title>
  46. </head>
  47. <body>
  48. <a href="https://github.com/mattbryson"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://s3.amazonaws.com/github/ribbons/forkme_right_white_ffffff.png" alt="Fork me on GitHub"></a>
  49. <div class="container">
  50. <script id='code_1'>
  51. $(function() {
  52. var tapCount=0;
  53. var doubleTapCount=0;
  54. var longTapCount=0;
  55. var swipeCount=0;
  56. var blackCount=0;
  57. //Enable swiping...
  58. $("#test").swipe( {
  59. tap:function(event, target) {
  60. tapCount++;
  61. msg(target);
  62. },
  63. doubleTap:function(event, target) {
  64. doubleTapCount++;
  65. msg(target);
  66. return true;
  67. },
  68. longTap:function(event, target) {
  69. longTapCount++;
  70. msg(target);
  71. },
  72. swipe:function() {
  73. swipeCount++;
  74. $("#textText").html("You swiped " + swipeCount + " times");
  75. },
  76. excludedElements:"",
  77. threshold:50
  78. });
  79. $("#test_btn").click(function() {
  80. window.open("http://www.google.com");
  81. });
  82. //Assign a click handler to a child of the touchSwipe object
  83. //This will require the jquery.ui.ipad.js to be picked up correctly.
  84. $("#another_div").click( function(){
  85. blackCount++;
  86. $("#another_div").html("<h3 id='div text'>jQuery click handler fired on the black div : you clicked the black div "+
  87. blackCount + " times</h3>");
  88. });
  89. function msg(target) {
  90. $("#textText").html("You tapped " + tapCount +", double tapped " + doubleTapCount + " and long tapped " + longTapCount + " times on " + $(target).attr("id"));
  91. }
  92. });
  93. </script>
  94. <span class='title'></span>
  95. <h4>events: <span class='events'><code>tap</code>, <code>doubleTap</code>, <code>longTap</code>, <code>swipe</code></span></h4>
  96. <h4>properties: <span class='properties'><code>longTapThreshold</code>, <code>doubleTapThreshold</code></span></h4>
  97. <p>You can also detect if the user simply taps and does not swipe with the <code>tap</code> handler<br/><br/>
  98. The <code>tap</code>, <code>doubleTap</code> and <code>longTap</code> handler are passed the original event object and the target that was clicked.
  99. <br/><br/>
  100. <b>See also the <a href="Hold.html"><code>hold</code></a> event for when a long tap reaches the <code>longTapThreshold</code></b>
  101. <br/>
  102. </p>
  103. <p class="muted">If you use the jquery.ui.ipad.js plugin (http://code.google.com/p/jquery-ui-for-ipad-and-iphone/) you can then also pickup
  104. standard jQuery mouse events on children of the touchSwipe object.</p>
  105. <p>You can set the delay between taps which defines a double tap, and the length of a long tap with the <code>doubleTapThreshold</code> and <code>longTapThreshold</code> properties.</p>
  106. <p>Note: If you assign both tap and double tap, you tap events will be delayed by the length of <code>doubleTapThreshold</code> as it waits to see if its a double before trigger the event</p>
  107. <p class="muted"><code>tap</code> replaces the old <code>click</code> handler for naming consistency. Since the introduction of event
  108. triggering as well as callbacks, the plugin cannot trigger a <code>click</code> event as it clashes with the jQ click event,
  109. so both the event and callback are called <code>tap</code>. For backwards compatibility, the <code>click</code> callback will still work
  110. but there is no click event. You must use the <code>tap</code> event when binding with <code>on</code> or <code>bind</code></p>
  111. <button class='btn btn-small btn-info example_btn'>Jump to Example</button>
  112. <pre class="prettyprint lang-js" data-src='code_1'></pre>
  113. <span class='navigation'></span>
  114. <div id="test" class="box">
  115. <div id="textText">Swipe, Tap, Double Tap or Long Tap me</div><br/>
  116. <small><a href="http://google.com" target="new">Open Google</a></small>
  117. <button id="test_btn">Open Google From a button</button>
  118. <div id="a_div" class="box" style="width:150px;height:50px;background:#666"><h3 id='a_div_text'>Im just a child div</h3></div>
  119. <div id="another_div" class="box" style="width:200px;height:100px;background:#000"><h3>Im a child div with my own jQuery click handler</h3></div>
  120. </div>
  121. <span class='navigation'></span>
  122. </div>
  123. </body>
  124. </html>
  125. </article>
  126. </section>
  127. </div>
  128. <br class="clear">
  129. <footer>
  130. Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Mon Sep 17 2018 13:09:45 GMT+0100 (British Summer Time) using the docdash theme.
  131. </footer>
  132. <script>prettyPrint();</script>
  133. <script src="scripts/linenumber.js"></script>
  134. </body>
  135. </html>