Advertisement
Guest User

Untitled

a guest
Feb 8th, 2016
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.25 KB | None | 0 0
  1. <div class="carousel">
  2.  
  3.  
  4. <div class="carousel__content">
  5. <div class="item">
  6. <p class="title">First</p>
  7. <img src="http://placehold.it/1800x850/70AD96/FFF&text=&nbsp;" alt="">
  8. </div>
  9. <div class="item">
  10. <p class="title">Second</p>
  11. <img src="http://placehold.it/1800x850/EA4E23/FFF&text=&nbsp;" alt="">
  12. </div>
  13. <div class="item">
  14. <p class="title">Third</p>
  15. <img src="http://placehold.it/1800x850/9BA452/FFF&text=&nbsp;" alt="">
  16. </div>
  17. <div class="item">
  18. <p class="title">Fourth</p>
  19. <img src="http://placehold.it/1800x850/472D38/FFF&text=&nbsp;" alt="">
  20. </div>
  21. <div class="item">
  22. <p class="title">Fifth</p>
  23. <img src="http://placehold.it/1800x850/F77C85/FFF&text=&nbsp;" alt="">
  24. </div>
  25. <div class="item">
  26. <p class="title">Sixth</p>
  27. <p class="title title--sub">Last Item</p>
  28. <img src="http://placehold.it/1800x850/00FFAE/FFF&text=&nbsp;" alt="">
  29. </div>
  30. </div>
  31.  
  32. <div class="carousel__nav">
  33. <a href="#" class="nav nav--left">Previous</a>
  34. <a href="#" class="nav nav--right">Next</a>
  35. </div>
  36.  
  37. ( function () {
  38. var carouselContent, carouselIndex, carouselLength, firstClone, firstItem, isAnimating, itemWidth, lastClone, lastItem;
  39. carouselContent = $('.carousel__content');
  40. carouselIndex = 0;
  41. carouselLength = carouselContent.children().length;
  42. isAnimating = false;
  43. itemWidth = 100 / carouselLength;
  44. firstItem = $(carouselContent.children()[0]);
  45. lastItem = $(carouselContent.children()[carouselLength - 1]);
  46. firstClone = null;
  47. lastClone = null;
  48. carouselContent.css('width', carouselLength * 100 + '%');
  49. carouselContent.transition({ x: carouselIndex * -itemWidth + '%' }, 0);
  50. $.each(carouselContent.children(), function () {
  51. return $(this).css('width', itemWidth + '%');
  52. });
  53. $('.nav--left').on('click', function () {
  54. if (isAnimating) {
  55. return;
  56. }
  57. isAnimating = true;
  58. carouselIndex--;
  59. if (carouselIndex === -1) {
  60. lastItem.prependTo(carouselContent);
  61. carouselContent.transition({ x: (carouselIndex + 2) * -itemWidth + '%' }, 0);
  62. return carouselContent.transition({ x: (carouselIndex + 1) * -itemWidth + '%' }, 1000, 'easeInOutExpo', function () {
  63. carouselIndex = carouselLength - 1;
  64. lastItem.appendTo(carouselContent);
  65. carouselContent.transition({ x: carouselIndex * -itemWidth + '%' }, 0);
  66. return isAnimating = false;
  67. });
  68. } else {
  69. return carouselContent.transition({ x: carouselIndex * -itemWidth + '%' }, 1000, 'easeInOutExpo', function () {
  70. return isAnimating = false;
  71. });
  72. }
  73. });
  74. $('.nav--right').on('click', function () {
  75. if (isAnimating) {
  76. return;
  77. }
  78. isAnimating = true;
  79. carouselIndex++;
  80. return carouselContent.transition({ x: carouselIndex * -itemWidth + '%' }, 1000, 'easeInOutExpo', function () {
  81. isAnimating = false;
  82. if (firstClone) {
  83. carouselIndex = 0;
  84. carouselContent.transition({ x: carouselIndex * -itemWidth + '%' }, 0);
  85. firstClone.remove();
  86. firstClone = null;
  87. carouselLength = carouselContent.children().length;
  88. itemWidth = 100 / carouselLength;
  89. carouselContent.css('width', carouselLength * 100 + '%');
  90. $.each(carouselContent.children(), function () {
  91. return $(this).css('width', itemWidth + '%');
  92. });
  93. return;
  94. }
  95. if (carouselIndex === carouselLength - 1) {
  96. carouselLength++;
  97. itemWidth = 100 / carouselLength;
  98. firstClone = firstItem.clone();
  99. firstClone.addClass('clone');
  100. firstClone.appendTo(carouselContent);
  101. carouselContent.css('width', carouselLength * 100 + '%');
  102. $.each(carouselContent.children(), function () {
  103. return $(this).css('width', itemWidth + '%');
  104. });
  105. return carouselContent.transition({ x: carouselIndex * -itemWidth + '%' }, 0);
  106. }
  107. });
  108. });
  109.  
  110. function skinsave_2016_slider() {
  111. wp_enqueue_script('skinsave_2016-slider-js', content_url('/js/slider-js.js'), array(), null, true);
  112. }
  113. add_action('wp_head', 'skinsave_2016_slider');
  114.  
  115. <script type="text/javascript" src="<?php bloginfo('skinsave_2016'); ?>/js/slider-js.js"></script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement