SerialScroll_paginator.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /*!******************************************
  2. Snippet for jQuery.SerialScroll
  3. --Generate a paginator based on the items--
  4. Suppose an HTML like this:
  5. <div id="container">
  6. ...
  7. <ul id="paginator" />
  8. <div id="pane">
  9. <img src="..." />
  10. <img src="..." />
  11. <img src="..." />
  12. <img src="..." />
  13. <img src="..." />
  14. </div>
  15. ...
  16. </div>
  17. You can use <ul>/<li> or any other HTML, just
  18. setup the selectors to match the elements.
  19. *********************************************/
  20. jQuery(function( $ ){
  21. var $pane = $('#pane'), //the item being scrolled
  22. $items = $pane.find('img'),//the items
  23. $paginator = $('#paginator');//the container of the links/buttons
  24. $('#pane').serialScroll({
  25. //...
  26. items: $items,//or just 'img'
  27. //...
  28. });
  29. $items.each(function(index){//index starts counting from 0
  30. var text = 'item ' + (index + 1);//here generate the text you want
  31. var $page = $('<li />').text( text ).appendTo($paginator);
  32. $page.click(function(e){
  33. //if you put a link inside the <li> then call:
  34. //e.preventDefault();
  35. $pane.trigger('goto',[index]);//scroll to the item number #index.
  36. });
  37. });
  38. });
  39. /*!**************************************************************************
  40. You can generate the paginators the way you want. They don't need to be <li>s
  41. You can add a link inside, or an image. Also, the 'this' will be the item so,
  42. you can take data from each one, and put it in the paginator.
  43. *****************************************************************************/