Advertisement
Guest User

kev999

a guest
Aug 23rd, 2014
249
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.91 KB | None | 0 0
  1. <script type="text/javascript">
  2. $(document).ready(function(e) {
  3. /*
  4. DIMENSIONS
  5. */
  6. gp_width = 0;
  7. $('#gallery .panel').each(function(index, element) {
  8. gp_width = gp_width+$(this).width();
  9. });
  10. p_width = $('#gallery .panel').width();
  11. /*
  12. WRAP PANELS
  13. */
  14. $('#gallery .panel').wrapAll('<div class="gallery-container"></div>');
  15. $('.gallery-container').width(gp_width)
  16. .css({
  17. 'position':'absolute',
  18. 'left':'0px',
  19. 'top':'0px'
  20. });
  21. /*
  22. FLOAT PANELS
  23. */
  24. $('#gallery .panel').css({
  25. 'float':'left',
  26. 'width':'720px'
  27. });
  28. /*
  29. CLONE CONTAINER
  30. */
  31. $('.gallery-container')
  32. .clone()
  33. .prependTo('#gallery')
  34. .css({
  35. 'left': gp_width*-1
  36. });
  37. /*
  38. FUNCTIONS
  39. */
  40. function galleryLeft() {
  41.  
  42. $('.gallery-container').each(function() {
  43. $(this).animate({
  44. 'left': $(this)[0].offsetLeft-p_width
  45. },1200,'swing',function() {
  46. if ($(this)[0].offsetLeft < ($(this).width())*-1) {
  47. $(this).css('left',$(this)[0].offsetLeft+($(this).width())*2);
  48. return;
  49. }
  50. })
  51. });
  52.  
  53. }
  54. function galleryRight() {
  55. $('.gallery-container').each(function() {
  56. $(this).animate({
  57. 'left': $(this)[0].offsetLeft+p_width
  58. },1200,'swing',function() {
  59. if ($(this)[0].offsetLeft >= ($(this).width())) {
  60. $(this).css('left',$(this).width()*-1);
  61. return;
  62. }
  63. })
  64. });
  65. }
  66. /*
  67. EVENTS
  68. */
  69. $('#gallery .nav .left').click(function(e) {
  70. stopAutoGallery();
  71. galleryLeft();
  72. startAutoGallery();
  73. });
  74. $('#gallery .nav .right').click(function(e) {
  75. stopAutoGallery();
  76. galleryRight();
  77. startAutoGallery() ;
  78. });
  79. /*
  80. AUTOSTART
  81. */
  82. var autoGallery;
  83. startAutoGallery();
  84.  
  85. function startAutoGallery() {
  86. autoGallery = setInterval(function(){galleryLeft()}, 4000);
  87. }
  88. function stopAutoGallery() {
  89. $('.gallery-container').promise().done(function() {
  90. clearInterval(autoGallery);
  91. });
  92. }
  93.  
  94.  
  95. });
  96. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement