index.html 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  5. <title>jQuery.SerialScroll</title>
  6. <meta name="keywords" content="javascript, jquery, plugins, scroll, navigation, slideshow, news, ticker, sections, sequential, prev, next, series, scrollTo, smooth, to, animation, overflow, element, window, effect, ariel, flesler, customizable" />
  7. <meta name="description" content="Demo of jQuery.SerialScroll. A jQuery plugin to quickly animate series of items, made by Ariel Flesler." />
  8. <meta name="robots" content="index,follow" />
  9. <link type="text/css" rel="stylesheet" href="css/style.css" />
  10. <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
  11. <script type="text/javascript" src="./js/jquery.scrollTo.min.js"></script>
  12. <script type="text/javascript" src="../jquery.serialScroll.js"></script>
  13. <script type="text/javascript">
  14. // Easing equation, borrowed from jQuery easing plugin
  15. // http://gsgd.co.uk/sandbox/jquery/easing/
  16. jQuery.easing.easeOutQuart = function (x, t, b, c, d) {
  17. return -c * ((t=t/d-1)*t*t*t - 1) + b;
  18. };
  19. jQuery(function( $ ){
  20. /**
  21. * Most jQuery.serialScroll's settings, actually belong to jQuery.ScrollTo, check it's demo for an example of each option.
  22. * @see http://flesler.demos.com/jquery/scrollTo/
  23. * You can use EVERY single setting of jQuery.ScrollTo, in the settings hash you send to jQuery.serialScroll.
  24. */
  25. /**
  26. * The plugin binds 6 events to the container to allow external manipulation.
  27. * prev, next, goto, start, stop and notify
  28. * You use them like this: $(your_container).trigger('next'), $(your_container).trigger('goto', [5]) (0-based index).
  29. * If for some odd reason, the element already has any of these events bound, trigger it with the namespace.
  30. */
  31. /**
  32. * IMPORTANT: this call to the plugin specifies ALL the settings (plus some of jQuery.ScrollTo)
  33. * This is done so you can see them. You DON'T need to specify the commented ones.
  34. * A 'target' is specified, that means that #screen is the context for target, prev, next and navigation.
  35. */
  36. $('#screen').serialScroll({
  37. target:'#sections',
  38. items:'li', // Selector to the items ( relative to the matched elements, '#sections' in this case )
  39. prev:'img.prev',// Selector to the 'prev' button (absolute!, meaning it's relative to the document)
  40. next:'img.next',// Selector to the 'next' button (absolute too)
  41. axis:'xy',// The default is 'y' scroll on both ways
  42. navigation:'#navigation li a',
  43. duration:700,// Length of the animation (if you scroll 2 axes and use queue, then each axis take half this time)
  44. force:true, // Force a scroll to the element specified by 'start' (some browsers don't reset on refreshes)
  45. //queue:false,// We scroll on both axes, scroll both at the same time.
  46. //event:'click',// On which event to react (click is the default, you probably won't need to specify it)
  47. //stop:false,// Each click will stop any previous animations of the target. (false by default)
  48. //lock:true, // Ignore events if already animating (true by default)
  49. //start: 0, // On which element (index) to begin ( 0 is the default, redundant in this case )
  50. //cycle:true,// Cycle endlessly ( constant velocity, true is the default )
  51. //step:1, // How many items to scroll each time ( 1 is the default, no need to specify )
  52. //jump:false, // If true, items become clickable (or w/e 'event' is, and when activated, the pane scrolls to them)
  53. //lazy:false,// (default) if true, the plugin looks for the items on each event(allows AJAX or JS content, or reordering)
  54. //interval:1000, // It's the number of milliseconds to automatically go to the next
  55. //constant:true, // constant speed
  56. onBefore:function( e, elem, $pane, $items, pos ){
  57. /**
  58. * 'this' is the triggered element
  59. * e is the event object
  60. * elem is the element we'll be scrolling to
  61. * $pane is the element being scrolled
  62. * $items is the items collection at this moment
  63. * pos is the position of elem in the collection
  64. * if it returns false, the event will be ignored
  65. */
  66. //those arguments with a $ are jqueryfied, elem isn't.
  67. e.preventDefault();
  68. if (this.blur) {
  69. this.blur();
  70. }
  71. },
  72. onAfter:function( elem ){
  73. //'this' is the element being scrolled ($pane) not jqueryfied
  74. }
  75. });
  76. /**
  77. * No need to have only one element in view, you can use it for slideshows or similar.
  78. * In this case, clicking the images, scrolls to them.
  79. * No target in this case, so the selectors are absolute.
  80. */
  81. $('#slideshow').serialScroll({
  82. items:'li',
  83. prev:'#screen2 a.prev',
  84. next:'#screen2 a.next',
  85. offset:-230, //when scrolling to photo, stop 230 before reaching it (from the left)
  86. start:1, //as we are centering it, start at the 2nd
  87. duration:1200,
  88. force:true,
  89. stop:true,
  90. lock:false,
  91. cycle:false, //don't pull back once you reach the end
  92. easing:'easeOutQuart', //use this easing equation for a funny effect
  93. jump: true //click on the images to scroll to them
  94. });
  95. /**
  96. * The call below, is just to show that you are not restricted to prev/next buttons
  97. * In this case, the plugin will react to a custom event on the container
  98. * You can trigger the event from the outside.
  99. */
  100. var $news = $('#news-ticker');//we'll re use it a lot, so better save it to a var.
  101. $news.serialScroll({
  102. items:'div',
  103. duration:2000,
  104. force:true,
  105. axis:'y',
  106. easing:'linear',
  107. lazy:true,// NOTE: it's set to true, meaning you can add/remove/reorder items and the changes are taken into account.
  108. interval:1, // yeah! I now added auto-scrolling
  109. step:2 // scroll 2 news each time
  110. });
  111. /**
  112. * The following you don't need to see, is just for the "Add 2 Items" and "Shuffle"" buttons
  113. * These exemplify the use of the option 'lazy'.
  114. */
  115. $('#add-news').click(function(){
  116. var
  117. $items = $news.find('div'),
  118. num = $items.length + 1;
  119. $items.slice(-2).clone().find('h4').each(function(i){
  120. $(this).text( 'News ' + (num + i) );
  121. }).end().appendTo($news);
  122. });
  123. $('#shuffle-news').click(function(){//don't shuffle the first, don't wanna deal with css
  124. var shuffled = $news.find('div').get().slice(1).sort(function(){
  125. return Math.round(Math.random())-0.5;//just a random number between -0.5 and 0.5
  126. });
  127. $(shuffled).appendTo($news);//add them all reordered
  128. });
  129. });
  130. </script>
  131. <style type="text/css">
  132. </style>
  133. </head>
  134. <body>
  135. <h1>jQuery.SerialScroll</h1>
  136. <div id="screen">
  137. <img class="prev" src="img/prev.gif" alt="prev" width="42" height="53" />
  138. <div id="navigation">
  139. <ul>
  140. <li><a href="#">Section 1</a></li>
  141. <li><a href="#">Section 3</a></li>
  142. <li><a href="#">Section 5</a></li>
  143. </ul>
  144. </div>
  145. <div id="sections">
  146. <ul>
  147. <li>
  148. <h2>Section 1</h2>
  149. <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Suspendisse et turpis sed metus fermentum pellentesque. Vestibulum auctor neque ac nunc elementum malesuada. Praesent non est sed libero vestibulum consectetuer. Sed vehicula. Vivamus quis tellus sit amet erat ultrices luctus. Fusce a ligula. Fusce viverra libero vitae velit. Aenean bibendum nibh non lorem. Suspendisse quis velit. Integer sit amet lacus. Curabitur tristique. Morbi eu lectus. Vestibulum tristique aliquam quam. Sed neque.</p>
  150. <p>Nulla facilisi. Quisque eleifend libero. Sed eros. Morbi vel leo. Morbi varius tincidunt sem. Nam sodales volutpat velit. Suspendisse potenti. Duis vehicula pede non nisi. Proin elit pede, ultrices non, ultrices quis, vulputate sit amet, magna. Praesent sodales pellentesque justo. Donec blandit, augue id convallis congue, magna libero hendrerit erat, id blandit est lorem a tellus. Vestibulum tincidunt lectus quis metus. Pellentesque placerat lacus in urna.</p>
  151. </li>
  152. <li>
  153. <h2>Section 2</h2>
  154. <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Suspendisse et turpis sed metus fermentum pellentesque. Vestibulum auctor neque ac nunc elementum malesuada. Praesent non est sed libero vestibulum consectetuer. Sed vehicula. Vivamus quis tellus sit amet erat ultrices luctus. Fusce a ligula. Fusce viverra libero vitae velit. Aenean bibendum nibh non lorem. Suspendisse quis velit. Integer sit amet lacus. Curabitur tristique. Morbi eu lectus. Vestibulum tristique aliquam quam. Sed neque.</p>
  155. <p>Nulla facilisi. Quisque eleifend libero. Sed eros. Morbi vel leo. Morbi varius tincidunt sem. Nam sodales volutpat velit. Suspendisse potenti. Duis vehicula pede non nisi. Proin elit pede, ultrices non, ultrices quis, vulputate sit amet, magna. Praesent sodales pellentesque justo. Donec blandit, augue id convallis congue, magna libero hendrerit erat, id blandit est lorem a tellus. Vestibulum tincidunt lectus quis metus. Pellentesque placerat lacus in urna.</p>
  156. </li>
  157. <li class="fallen">
  158. <h2>Section 3</h2>
  159. <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Suspendisse et turpis sed metus fermentum pellentesque. Vestibulum auctor neque ac nunc elementum malesuada. Praesent non est sed libero vestibulum consectetuer. Sed vehicula. Vivamus quis tellus sit amet erat ultrices luctus. Fusce a ligula. Fusce viverra libero vitae velit. Aenean bibendum nibh non lorem. Suspendisse quis velit. Integer sit amet lacus. Curabitur tristique. Morbi eu lectus. Vestibulum tristique aliquam quam. Sed neque.</p>
  160. <p>Nulla facilisi. Quisque eleifend libero. Sed eros. Morbi vel leo. Morbi varius tincidunt sem. Nam sodales volutpat velit. Suspendisse potenti. Duis vehicula pede non nisi. Proin elit pede, ultrices non, ultrices quis, vulputate sit amet, magna. Praesent sodales pellentesque justo. Donec blandit, augue id convallis congue, magna libero hendrerit erat, id blandit est lorem a tellus. Vestibulum tincidunt lectus quis metus. Pellentesque placerat lacus in urna.</p>
  161. </li>
  162. <li>
  163. <h2>Section 4</h2>
  164. <p>Nullam et sem eget massa pellentesque dapibus. Nulla sollicitudin enim quis odio. Quisque ipsum lorem, volutpat eget, condimentum ac, posuere id, risus. Suspendisse tortor metus, aliquet in, varius nec, hendrerit a, libero. Suspendisse iaculis. Fusce commodo urna ut enim. Fusce tempus eros. Phasellus sodales tellus id dolor. Integer sollicitudin, turpis ac interdum condimentum, enim enim tempus metus, sed imperdiet massa diam nec elit. Mauris ante augue, hendrerit non, commodo ac, porttitor eu, turpis.</p>
  165. <p>In fermentum nibh ut diam. Mauris sagittis, tellus ac molestie fermentum, arcu orci pharetra mi, id vehicula massa leo vel pede. Nullam semper tincidunt lorem. Proin arcu libero, auctor sed, interdum egestas, ullamcorper et, lacus. Donec id lectus eget diam accumsan ullamcorper. Donec at urna et lacus condimentum pellentesque. Phasellus dapibus hendrerit massa. Sed sed ipsum. Quisque venenatis. Donec vel turpis.</p>
  166. </li>
  167. <li>
  168. <h2>Section 5</h2>
  169. <p>Nullam et sem eget massa pellentesque dapibus. Nulla sollicitudin enim quis odio. Quisque ipsum lorem, volutpat eget, condimentum ac, posuere id, risus. Suspendisse tortor metus, aliquet in, varius nec, hendrerit a, libero. Suspendisse iaculis. Fusce commodo urna ut enim. Fusce tempus eros. Phasellus sodales tellus id dolor. Integer sollicitudin, turpis ac interdum condimentum, enim enim tempus metus, sed imperdiet massa diam nec elit. Mauris ante augue, hendrerit non, commodo ac, porttitor eu, turpis.</p>
  170. <p>In fermentum nibh ut diam. Mauris sagittis, tellus ac molestie fermentum, arcu orci pharetra mi, id vehicula massa leo vel pede. Nullam semper tincidunt lorem. Proin arcu libero, auctor sed, interdum egestas, ullamcorper et, lacus. Donec id lectus eget diam accumsan ullamcorper. Donec at urna et lacus condimentum pellentesque. Phasellus dapibus hendrerit massa.</p>
  171. </li>
  172. </ul>
  173. </div>
  174. <img class="next" src="img/next.gif" alt="next" width="42" height="53" />
  175. </div>
  176. <p class="separator message">
  177. This plugin can be used for navigation purposes. You decide how many to show at a time with CSS.<br />
  178. The items don't need to be aligned, you can spread them as much as you want, it will always find them :)<br />
  179. Check jQuery.ScrollTo's demo if you want to create the perfect animation. You can use its settings too!
  180. </p>
  181. <div id="screen2">
  182. <div id="buttons">
  183. <a class="prev" href="#">Previous</a>
  184. <a class="next" href="#">Next</a>
  185. <br class="clear" />
  186. </div>
  187. <div id="slideshow">
  188. <ul>
  189. <li><img width="225" height="300" src="http://lorempixel.com/225/300/abstract" /></li>
  190. <li><img width="225" height="300" src="http://lorempixel.com/225/300/animals" /></li>
  191. <li><img width="225" height="300" src="http://lorempixel.com/225/300/business" /></li>
  192. <li><img width="225" height="300" src="http://lorempixel.com/225/300/cats" /></li>
  193. <li><img width="225" height="300" src="http://lorempixel.com/225/300/city" /></li>
  194. <li><img width="225" height="300" src="http://lorempixel.com/225/300/food" /></li>
  195. <li><img width="225" height="300" src="http://lorempixel.com/225/300/nightlife" /></li>
  196. <li><img width="225" height="300" src="http://lorempixel.com/225/300/fashion" /></li>
  197. <li><img width="225" height="300" src="http://lorempixel.com/225/300/people" /></li>
  198. <li><img width="225" height="300" src="http://lorempixel.com/225/300/nature" /></li>
  199. <li><img width="225" height="300" src="http://lorempixel.com/225/300/sports" /></li>
  200. <li><img width="225" height="300" src="http://lorempixel.com/225/300/technics" /></li>
  201. <li><img width="225" height="300" src="http://lorempixel.com/225/300/transport" /></li>
  202. </ul>
  203. </div>
  204. </div>
  205. <p class="separator message">
  206. You can also build slideshows with it. In this case, I centered the photos and made them clickable.<br />
  207. I set this one to cycle, try going over the last photo. I'm using a special easing equation.<br />
  208. You are allowed to interrupt the animation by clicking again. You can't do that in the first one.
  209. </p>
  210. <div id="ticker-container">
  211. <button id="add-news">Append 2 Items</button>
  212. <button id="shuffle-news">Shuffle</button>
  213. <div id="news-ticker">
  214. <div class="first">
  215. <h4>News 1</h4>
  216. <p>Nullam a leo. Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas mollis vestibulum purus, rutrum sed.</p>
  217. </div>
  218. <div>
  219. <h4>News 2</h4>
  220. <p>Phasellus nunc ipsum, faucibus non, iaculis ac, sagittis malesuada, augue. Aliquam sollicitudin. Cras iaculis lorem sit amet.</p>
  221. </div>
  222. <div>
  223. <h4>News 3</h4>
  224. <p>Morbi condimentum. Sed id nunc eu arcu aliquet bibendum. Maecenas vestibulum eros fringilla tortor. Nunc purus.</p>
  225. </div>
  226. <div>
  227. <h4>News 4</h4>
  228. <p>Sed condimentum. Duis orci. Ut odio leo, dapibus pretium, rhoncus a, sodales eu, nibh. Vivamus consectetuer vestibulum.</p>
  229. </div>
  230. <div>
  231. <h4>News 5</h4>
  232. <p>Pellentesque varius ligula et enim. Nulla ut purus vel magna ullamcorper vestibulum. Aliquam at enim at ligula bibendum.</p>
  233. </div>
  234. <div>
  235. <h4>News 6</h4>
  236. <p>Suspendisse id quam at lectus placerat dignissim. Praesent nulla urna, rutrum sed. Maecenas vitae libero ac elit.</p>
  237. </div>
  238. <div>
  239. <h4>News 7</h4>
  240. <p>Etiam aliquet. Nulla consectetuer, nibh ut gravida consectetuer, nisl enim vestibulum nibh. Suspendisse potenti.</p>
  241. </div>
  242. <div>
  243. <h4>News 8</h4>
  244. <p>Aliquam porta, nisi id aliquam posuere, enim mi bibendum tellus, non venenatis nisi orci at mi. Curabitur placerat.</p>
  245. </div>
  246. </div>
  247. </div>
  248. <p class="separator message">
  249. It can be used for news tickers as well. The plugin is not restricted to clicks or buttons.<br />
  250. Here the option 'lazy' is used and it works, click the buttons on the right if you don't trust me :)<br />
  251. You can also specify an interval for auto scrolling. To stop the animation, use $().stop() on the container.
  252. </p>
  253. <p id="general" class="side message">
  254. This demo shows 3 different uses of this plugin. It can certainly be used for others purposes as well.<br />
  255. Note that it can be used with any html. This is not a widget and the examples are just improvised.<br />
  256. Use "View source" to see the different calls and markup. All the settings are commented.
  257. </p>
  258. <p id="extra" class="side message">
  259. This plugin won't modify your html at all, won't even touch a single style.<br />
  260. It gives you full control over the markup and the look, that's your part of the job :)<br />
  261. You can control the animation from outside with the 3 exposed events (prev, next, goto).<br />
  262. Guess what ? If you manage to show them scrollbars, users with no javascript can still navigate your content!
  263. </p>
  264. <div id="links">
  265. <h3>Links</h3>
  266. <ul>
  267. <li><a target="_blank" href="https://github.com/flesler/jquery.serialScroll">Github</a></li>
  268. <li><a target="_blank" href="http://flesler.blogspot.com/2008/02/jqueryserialscroll.html">Documentation</a></li>
  269. <li><a href="http://demos.flesler.com/jquery/scrollTo/" rel="prev" rev="next" type="text/html">jQuery.scrollTo's Demo</a></li>
  270. </ul>
  271. </div>
  272. </body>
  273. </html>