Tap_vs_swipe.html 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <!DOCTYPE HTML>
  2. <html>
  3. <head>
  4. <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
  5. <meta http-equiv="x-ua-compatible" content="IE=9">
  6. <link href="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.2.2/css/bootstrap-combined.min.css" rel="stylesheet">
  7. <link href="http://twitter.github.com/bootstrap/assets/js/google-code-prettify/prettify.css" rel="stylesheet" />
  8. <link href="css/main.css" type="text/css" rel="stylesheet" />
  9. <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
  10. <script type="text/javascript" src="https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js"></script>
  11. <script type="text/javascript" src="../jquery.touchSwipe.js"></script>
  12. <script type="text/javascript" src="js/main.js"></script>
  13. <!-- use the jquery.ui.ipad.js plugin to translate touch events to mouse events -->
  14. <script type="text/javascript" src="js/jquery.ui.ipad.js"></script>
  15. <title>touchSwipe</title>
  16. </head>
  17. <body>
  18. <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>
  19. <div class="container">
  20. <script id='code_1'>
  21. $(function() {
  22. var tapCount=0;
  23. var doubleTapCount=0;
  24. var longTapCount=0;
  25. var swipeCount=0;
  26. var blackCount=0;
  27. //Enable swiping...
  28. $("#test").swipe( {
  29. tap:function(event, target) {
  30. tapCount++;
  31. msg(target);
  32. },
  33. doubleTap:function(event, target) {
  34. doubleTapCount++;
  35. msg(target);
  36. return true;
  37. },
  38. longTap:function(event, target) {
  39. longTapCount++;
  40. msg(target);
  41. },
  42. swipe:function() {
  43. swipeCount++;
  44. $("#textText").html("You swiped " + swipeCount + " times");
  45. },
  46. excludedElements:"",
  47. threshold:50
  48. });
  49. $("#test_btn").click(function() {
  50. window.open("http://www.google.com");
  51. });
  52. //Assign a click handler to a child of the touchSwipe object
  53. //This will require the jquery.ui.ipad.js to be picked up correctly.
  54. $("#another_div").click( function(){
  55. blackCount++;
  56. $("#another_div").html("<h3 id='div text'>jQuery click handler fired on the black div : you clicked the black div "+
  57. blackCount + " times</h3>");
  58. });
  59. function msg(target) {
  60. $("#textText").html("You tapped " + tapCount +", double tapped " + doubleTapCount + " and long tapped " + longTapCount + " times on " + $(target).attr("id"));
  61. }
  62. });
  63. </script>
  64. <span class='title'></span>
  65. <h4>events: <span class='events'><code>tap</code>, <code>doubleTap</code>, <code>longTap</code>, <code>swipe</code></span></h4>
  66. <h4>properties: <span class='properties'><code>longTapThreshold</code>, <code>doubleTapThreshold</code></span></h4>
  67. <p>You can also detect if the user simply taps and does not swipe with the <code>tap</code> handler<br/><br/>
  68. The <code>tap</code>, <code>doubleTap</code> and <code>longTap</code> handler are passed the original event object and the target that was clicked.
  69. <br/><br/>
  70. <b>See also the <a href="Hold.html"><code>hold</code></a> event for when a long tap reaches the <code>longTapThreshold</code></b>
  71. <br/>
  72. </p>
  73. <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
  74. standard jQuery mouse events on children of the touchSwipe object.</p>
  75. <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>
  76. <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>
  77. <p class="muted"><code>tap</code> replaces the old <code>click</code> handler for naming consistency. Since the introduction of event
  78. triggering as well as callbacks, the plugin cannot trigger a <code>click</code> event as it clashes with the jQ click event,
  79. so both the event and callback are called <code>tap</code>. For backwards compatibility, the <code>click</code> callback will still work
  80. 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>
  81. <button class='btn btn-small btn-info example_btn'>Jump to Example</button>
  82. <pre class="prettyprint lang-js" data-src='code_1'></pre>
  83. <span class='navigation'></span>
  84. <div id="test" class="box">
  85. <div id="textText">Swipe, Tap, Double Tap or Long Tap me</div><br/>
  86. <small><a href="http://google.com" target="new">Open Google</a></small>
  87. <button id="test_btn">Open Google From a button</button>
  88. <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>
  89. <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>
  90. </div>
  91. <span class='navigation'></span>
  92. </div>
  93. </body>
  94. </html>