tutorial-Image_gallery_example.html 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>Tutorial: Image gallery example - 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: Image gallery example</h1>
  26. <section>
  27. <header>
  28. <h2>Image gallery example</h2>
  29. </header>
  30. <article>
  31. <!DOCTYPE HTML>
  32. <html lang="en">
  33. <head>
  34. <meta charset="utf-8">
  35. <meta name="viewport"
  36. content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
  37. <meta http-equiv="x-ua-compatible" content="IE=9">
  38. <link href="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.2.2/css/bootstrap-combined.min.css" rel="stylesheet">
  39. <link href="http://twitter.github.com/bootstrap/assets/js/google-code-prettify/prettify.css" rel="stylesheet"/>
  40. <link href="css/main.css" type="text/css" rel="stylesheet"/>
  41. <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
  42. <script type="text/javascript"
  43. src="https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js"></script>
  44. <script type="text/javascript" src="../jquery.touchSwipe.js"></script>
  45. <script type="text/javascript" src="js/main.js"></script>
  46. <title>touchSwipe</title>
  47. <style>
  48. #content {
  49. height: 340px;
  50. width: 500px;
  51. overflow: hidden;
  52. position: relative;
  53. border: 1px solid black;
  54. }
  55. #imgs {
  56. float: left;
  57. display: inline;
  58. padding: 0;
  59. margin: 0;
  60. width: 1510px;
  61. transition-property: transform;
  62. transition-duration: 0.5s;
  63. transition-timing-function: ease-out;
  64. /*apply a transform to kick in the hardware acceleration. Without this, the first
  65. time we add the transform you get odd rendering of the divs (half missing) */
  66. transform: translate(0, 0);
  67. }
  68. #imgs img {
  69. padding: 0;
  70. margin: 0;
  71. width: 500px;
  72. height: 340px;
  73. /*apply a transform to kick in the hardware acceleration. Without this, the first
  74. time we add the transform you get odd rendering of the divs (half missing) */
  75. transform: translate(0, 0);
  76. }
  77. </style>
  78. <script id='code_1'>
  79. var IMG_WIDTH = 500;
  80. var currentImg = 0;
  81. var maxImages = 3;
  82. var speed = 500;
  83. var imgs;
  84. var swipeOptions = {
  85. triggerOnTouchEnd: true,
  86. swipeStatus: swipeStatus,
  87. allowPageScroll: "vertical",
  88. threshold: 75
  89. };
  90. $(function () {
  91. imgs = $("#imgs");
  92. imgs.swipe(swipeOptions);
  93. });
  94. /**
  95. * Catch each phase of the swipe.
  96. * move : we drag the div
  97. * cancel : we animate back to where we were
  98. * end : we animate to the next image
  99. */
  100. function swipeStatus(event, phase, direction, distance) {
  101. //If we are moving before swipe, and we are going L or R in X mode, or U or D in Y mode then drag.
  102. if (phase == "move" && (direction == "left" || direction == "right")) {
  103. var duration = 0;
  104. if (direction == "left") {
  105. scrollImages((IMG_WIDTH * currentImg) + distance, duration);
  106. } else if (direction == "right") {
  107. scrollImages((IMG_WIDTH * currentImg) - distance, duration);
  108. }
  109. } else if (phase == "cancel") {
  110. scrollImages(IMG_WIDTH * currentImg, speed);
  111. } else if (phase == "end") {
  112. if (direction == "right") {
  113. previousImage();
  114. } else if (direction == "left") {
  115. nextImage();
  116. }
  117. }
  118. }
  119. function previousImage() {
  120. currentImg = Math.max(currentImg - 1, 0);
  121. scrollImages(IMG_WIDTH * currentImg, speed);
  122. }
  123. function nextImage() {
  124. currentImg = Math.min(currentImg + 1, maxImages - 1);
  125. scrollImages(IMG_WIDTH * currentImg, speed);
  126. }
  127. /**
  128. * Manually update the position of the imgs on drag
  129. */
  130. function scrollImages(distance, duration) {
  131. imgs.css("transition-duration", (duration / 1000).toFixed(1) + "s");
  132. //inverse the number we set in the css
  133. var value = (distance < 0 ? "" : "-") + Math.abs(distance).toString();
  134. imgs.css("transform", "translate(" + value + "px,0)");
  135. }
  136. </script>
  137. </head>
  138. <body>
  139. <a href="https://github.com/mattbryson"><img style="position: absolute; top: 0; right: 0; border: 0;"
  140. src="https://s3.amazonaws.com/github/ribbons/forkme_right_white_ffffff.png"
  141. alt="Fork me on GitHub"></a>
  142. <div class="container">
  143. <p>Below is a very simple image gallery to demonstrate how to implement touchSwipe.<br/><br/>
  144. Swipe the images below left and right. Swipe up and down will scroll the page. Uses HTML5
  145. CSS to animate.</p>
  146. <br/>
  147. <div id="content">
  148. <div id="imgs">
  149. <img src="https://lh4.googleusercontent.com/_D9-nzLCi9qU/TNQ2hYNqQEI/AAAAAAAADtI/TcqCdc6N26A/s500/twick_pool_stairs~.jpg"/>
  150. <img src="https://lh6.googleusercontent.com/_D9-nzLCi9qU/TNQ2gdP8JYI/AAAAAAAADtI/NU2WBbaXpgU/s500/twick_pool_stairsAndChanginRoom~.jpg"/>
  151. <img src="https://lh4.googleusercontent.com/_D9-nzLCi9qU/TNQ2UWpqLgI/AAAAAAAADtI/-OG4z6RxHwA/s500/twick_pool_hall~.jpg"/>
  152. </div>
  153. </div>
  154. </div>
  155. </body>
  156. </html>
  157. </article>
  158. </section>
  159. </div>
  160. <br class="clear">
  161. <footer>
  162. 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.
  163. </footer>
  164. <script>prettyPrint();</script>
  165. <script src="scripts/linenumber.js"></script>
  166. </body>
  167. </html>