Guest User

Untitled

a guest
Oct 17th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.82 KB | None | 0 0
  1. out+='<div class="col-lg-5 prod-slides">';
  2. out+='<div id="sync1" class="owl-carousel owl-theme">';
  3. out+='<div class="item">';
  4. out+=`<img src="pages/orderPage/goods/${pack.img}">`;
  5. out+='</div>';
  6. out+='<div class="item">';
  7. out+=`<img src="pages/orderPage/goods/${pack.img}">`;
  8. out+='</div>';
  9. out+='<div class="item">';
  10. out+=`<img src="pages/orderPage/goods/${pack.img}">`;
  11. out+='</div>';
  12. out+='</div>';
  13.  
  14. out+='<div id="sync2" class="owl-carousel owl-theme">';
  15. out+='<div class="item">';
  16. out+=`<img src="pages/orderPage/goods/${pack.img}">`;
  17. out+='</div>';
  18. out+='<div class="item">';
  19. out+=`<img src="pages/orderPage/goods/${pack.img}">`;
  20. out+='</div>';
  21. out+='<div class="item">';
  22. out+=`<img src="pages/orderPage/goods/${pack.img}">`;
  23. out+='</div>';
  24. out+='</div>';
  25.  
  26. #sync1.owl-theme {
  27. position: relative;
  28. }
  29.  
  30. #sync1.owl-theme .owl-next, .owl-prev {
  31. width: 30px;
  32. height
  33.  
  34. : auto;
  35. top:50%;
  36. position: absolute;
  37. outline: none;
  38. }
  39. .owl-dots{
  40. display: none;
  41. }
  42. .owl-nav span{
  43. display: block;
  44. top:50%;
  45. font-size: 35px;
  46. }
  47. #sync1.owl-theme .owl-prev{
  48. right: auto;
  49. }
  50. #sync1.owl-theme .owl-next{
  51. left: auto;
  52. }
  53. .owl-item{
  54. padding-top: 20px;
  55. }
  56.  
  57. #sync1 .item{
  58. width: 250px;
  59. }
  60. #sync2 .item{
  61. width: 125px;
  62. }
  63. #sync1 .active{
  64. display: flex;
  65. }
  66. #sync1 .active .item{
  67. margin: auto;
  68. }
  69.  
  70. $(document).ready(function() {
  71.  
  72. var sync1 = $("#sync1");
  73. var sync2 = $("#sync2");
  74. var slidesPerPage = 3; //globaly define number of elements per page
  75. var syncedSecondary = true;
  76.  
  77. sync1.owlCarousel({
  78. items : 1,
  79.  
  80. nav: true,
  81.  
  82. loop: true,
  83. responsiveRefreshRate : 200,
  84.  
  85. }).on('changed.owl.carousel', syncPosition);
  86.  
  87.  
  88. sync2.on('initialized.owl.carousel', function () {
  89. sync2.find(".owl-item").eq(0).addClass("current");
  90. })
  91. .owlCarousel({
  92. items : slidesPerPage,
  93. margin:20,
  94. nav: true,
  95. slideBy: slidesPerPage, //alternatively you can slide by 1, this way the active slide will stick to the first item in the second carousel
  96. responsiveRefreshRate : 100
  97. }).on('changed.owl.carousel', syncPosition2);
  98.  
  99. function syncPosition(el) {
  100. //if you set loop to false, you have to restore this next line
  101. //var current = el.item.index;
  102.  
  103. //if you disable loop you have to comment this block
  104. var count = el.item.count-1;
  105. var current = Math.round(el.item.index - (el.item.count/2) - .5);
  106.  
  107. if(current < 0) {
  108. current = count;
  109. }
  110. if(current > count) {
  111. current = 0;
  112. }
  113.  
  114. //end block
  115.  
  116. sync2
  117. .find(".owl-item")
  118. .removeClass("current")
  119. .eq(current)
  120. .addClass("current");
  121. var onscreen = sync2.find('.owl-item.active').length - 1;
  122. var start = sync2.find('.owl-item.active').first().index();
  123. var end = sync2.find('.owl-item.active').last().index();
  124.  
  125. if (current > end) {
  126. sync2.data('owl.carousel').to(current, 100, true);
  127. }
  128. if (current < start) {
  129. sync2.data('owl.carousel').to(current - onscreen, 100, true);
  130. }
  131. }
  132.  
  133. function syncPosition2(el) {
  134. if(syncedSecondary) {
  135. var number = el.item.index;
  136. sync1.data('owl.carousel').to(number, 100, true);
  137. }
  138. }
  139.  
  140. sync2.on("click", ".owl-item", function(e){
  141. e.preventDefault();
  142. var number = $(this).index();
  143. sync1.data('owl.carousel').to(number, 300, true);
  144. });
  145. });
  146.  
  147. .owl-stage{
  148. width: initial !important;
  149. }
Add Comment
Please, Sign In to add comment