Trigger_handlers.html 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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. <title>touchSwipe</title>
  14. </head>
  15. <body>
  16. <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>
  17. <div class="container">
  18. <script id='code_1'>
  19. $(function() {
  20. //Enable swiping...
  21. $("#test").swipe( {
  22. swipeStatus:function(event, phase, direction, distance)
  23. {
  24. var str = "";
  25. if (phase=="move")
  26. str="You have moved " + distance +" pixels, past 200 and the handler will fire";
  27. if (phase=="end")
  28. str="Handler fired, you swiped " + direction;
  29. $(this).text(str);
  30. },
  31. triggerOnTouchEnd:false,
  32. threshold:200
  33. });
  34. });
  35. </script>
  36. <script id='code_2'>
  37. $(function() {
  38. $("#test2").swipe( {
  39. swipeStatus:function(event, phase, direction, distance, duration)
  40. {
  41. var str = "";
  42. if (phase=="move")
  43. str="You have moved for " + duration +" ms, If you go over 5000 the swipe will cancel";
  44. if (phase=="cancel")
  45. str="You took to long and the swipe was canceled";
  46. if (phase=="end")
  47. str="Handler fired, you swiped " + direction;
  48. $(this).text(str);
  49. },
  50. triggerOnTouchEnd:false,
  51. maxTimeThreshold:5000,
  52. threshold:null
  53. });
  54. });
  55. </script>
  56. <script id='code_3'>
  57. $(function() {
  58. $("#test3").swipe( {
  59. swipeStatus:function(event, phase, direction, distance, duration)
  60. {
  61. var str = "";
  62. if (phase=="move")
  63. str="You have moved " + distance +" px, If you leave the swipe object, the swipe will end";
  64. if (phase=="end")
  65. str="The swipe has ended"
  66. $(this).text(str);
  67. },
  68. triggerOnTouchLeave:true,
  69. threshold:null
  70. });
  71. });
  72. </script>
  73. <script id='code_4'>
  74. $(function() {
  75. $("#test4").swipe( {
  76. swipeStatus:function(event, phase, direction, distance, duration)
  77. {
  78. var str = "";
  79. if (phase=="move") {
  80. str="You have moved " + distance +" pixels, past 200 and the handler will fire <br/>";
  81. str+="You have moved for " + duration +" ms, If you go over 5000 the swipe will cancel <br/>";
  82. str+="If you leave the swipe object, and have made the distance, the swipe will end <br/>";
  83. str+="If you leave the swipe object, and have NOT made the distance, the swipe will cancel ";
  84. }
  85. if (phase=="end") {
  86. str="Handler fired, you met the thresholds:<br/>";
  87. str+=distance+"px (over 500px required) <br/>";
  88. str+=duration+"ms (under 5000ms required) <br/>";
  89. }
  90. if (phase=="cancel") {
  91. str="You didn't meet the thresholds, cancel was fired:<br/>";
  92. str+=distance+"px (over 500px required) <br/>";
  93. str+=duration+"ms (under 5000ms required) <br/>";
  94. }
  95. $(this).html(str);
  96. },
  97. triggerOnTouchEnd:false,
  98. triggerOnTouchLeave:true,
  99. maxTimeThreshold:5000,
  100. threshold:500
  101. });
  102. });
  103. </script>
  104. <span class='title'></span>
  105. <h4>properties: <span class='properties'><code>triggerOnTouchEnd</code>, <code>triggerOnTouchLeave</code></span></h4>
  106. <p>With <code>triggerOnTouchEnd</code> you can trigger the <code>swipe</code> end handler either when the user releases (default) or when the user has swiped the distance / time of the thresholds (but is still swiping).</p>
  107. <p>With <code>triggerOnTouchLeave</code> you can end the event if the user swipes off the element</p>
  108. <p>Swipe below, and the swipeEnd handler will trigger when you have swiped 200 px.</p>
  109. <button class='btn btn-small btn-info example_btn'>Jump to Example</button>
  110. <pre class="prettyprint lang-js" data-src="code_1"></pre>
  111. <script>getNavigation();</script>
  112. <div id="test" class="box">Swipe over 200px and the swipe event will fire</div>
  113. <pre class="prettyprint lang-js" data-src="code_2"></pre>
  114. <span class='navigation'></span>
  115. <div id="test2" class="box">Swipe in under 5000ms and the swipe event will fire</div>
  116. <pre class="prettyprint lang-js" data-src="code_3"></pre>
  117. <span class='navigation'></span>
  118. <div id="test3" class="box">Swipe out of this box and the swipe event will end</div>
  119. <pre class="prettyprint lang-js" data-src="code_4"></pre>
  120. <span class='navigation'></span>
  121. <div id="test4" class="box">Time, distance and trigger on END and trigger on Leave set..</div>
  122. <span class='navigation'></span>
  123. </div>
  124. </body>
  125. </html>