Thresholds.html 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. $("#test").swipe( {
  21. swipe:function(event, direction) {
  22. $(this).text("You swiped " + direction);
  23. },
  24. swipeStatus:function(event, phase) {
  25. if (phase=="cancel") {
  26. $(this).text("You didnt swipe far enough ");
  27. }
  28. },
  29. threshold:200
  30. });
  31. });
  32. </script>
  33. <script id='code_2'>
  34. $(function() {
  35. $("#test2").swipe( {
  36. swipe:function(event, direction) {
  37. $(this).text("You swiped " + direction );
  38. },
  39. swipeStatus:function(event, phase) {
  40. if (phase=="cancel") {
  41. $("#test2").text("Your swipe was too slow ");
  42. }
  43. },
  44. maxTimeThreshold:1000,
  45. threshold:null,
  46. triggerOnTouchEnd:false
  47. });
  48. });
  49. </script>
  50. <script id='code_3'>
  51. $(function() {
  52. $("#test3").swipe( {
  53. swipe:function(event, direction) {
  54. $(this).text("You swiped " + direction );
  55. },
  56. swipeStatus:function(event, phase, direction, distance, duration, fingers) {
  57. $("#test3").text(" Your have swiped " + distance + " px so far");
  58. if(distance>200) {
  59. $("#test3").text(" Now swipe back 10px and release to cancel.. distance = " + distance + "px");
  60. }
  61. if (phase=="cancel") {
  62. $("#test3").text(" You cancelled the swipe");
  63. }
  64. },
  65. threshold:200,
  66. cancelThreshold:10
  67. });
  68. });
  69. </script>
  70. <span class='title'></span>
  71. <h4>property: <span class='properties'><code>threshold</code></span></h4>
  72. <p>By setting the <code>threshold</code> you can set how far the user must swipe before it is considered a swipe. <br/>Swipe at least 200px</p>
  73. <button class='btn btn-small btn-info example_btn'>Jump to Example</button>
  74. <pre class="prettyprint lang-js" data-src="code_1"></pre>
  75. <span class='navigation'></span>
  76. <div id="test" class="box">Swipe me for at least 200 px</div>
  77. <h4>property: <span class='properties'><code>cancelThreshold</code></span><h4>
  78. <p>By setting the <code>cancelThreshold</code> you can set the minimum distance in px that the user needs to swipe back to cancel the current swipe, even if they have passed the main <code>threshold</code></p>
  79. <pre class="prettyprint lang-js" data-src="code_3"></pre>
  80. <div id="test3" class='box'>Swipe me for at least 200 px, then back 10px to cancel</div>
  81. <h4>property: <span class='properties'><code>maxTimeThreshold</code></span><h4>
  82. <p>By setting the <code>maxTimeThreshold</code> you can set the maximum time the user has to complete the swipe. A swipe LONGER than this is cancelled. This can be useful for ignoring long slow swipes. <br/>Swipe in under 500ms</p>
  83. <pre class="prettyprint lang-js" data-src="code_2"></pre>
  84. <div id="test2" class='box'>Swipe me within 1000 ms</div>
  85. <span class='navigation'></span>
  86. </div>
  87. </body>
  88. </html>