Advertisement
neatekFb

Set `owl-center` class for middle item - OwlCarousel2

Jun 28th, 2017
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Vladimir Zhelnov // neatek.ru // neatek.pw
  2. // js - owl-center Class for middle item
  3. // https://owlcarousel2.github.io/OwlCarousel2/
  4. var owl = $('.owl-carousel-2');
  5. owl.owlCarousel({
  6.     loop:true,
  7.     margin:0,
  8.     dots:false,
  9.     nav:true,
  10.     autoplay: true,
  11.     autoplaySpeed: 800,
  12.     navText: ['<i class="fa fa-angle-left" aria-hidden="true"></i>','<i class="fa fa-angle-right" aria-hidden="true"></i>'], //font-awesome http://fontawesome.io/
  13.       items : 1, // IMPORTANT
  14.       responsive : {
  15.         480 : { items : 1  },
  16.         800 : { items : 2  },
  17.         1024 : { items : 3 }
  18.       }
  19. });
  20.  
  21. // Function for detect center item FOR 3 ITEMS (Change i==1) for your element
  22. function set_owl_center() {
  23.     owl.find( ".active" ).removeClass('owl-center');
  24.     setTimeout(function(){
  25.       owl.find( ".active" ).each(function( i ) {
  26.         if(i==1) $(this).addClass('owl-center');
  27.       });
  28.     }, 80);
  29. }
  30.  
  31. set_owl_center(); // Init center
  32.  
  33. owl.on('changed.owl.carousel', function(event) {set_owl_center();}) // On changes
  34.  
  35. /* HTML
  36.                 <div class="owl-carousel-2 owl-theme">
  37.                     <div class="item"><img src="./assets/img/slider1.jpg"></div>
  38.                     <div class="item"><img src="./assets/img/slider1.jpg"></div>
  39.                     <div class="item"><img src="./assets/img/slider1.jpg"></div>
  40.                 </div>
  41. */
  42.  
  43. /* CSS
  44. .owl-item img {
  45.     opacity: 0.5;
  46.     transition: 0.3s;
  47. }
  48. .owl-carousel-2 .owl-center img {
  49.     opacity: 1.0;
  50. }
  51.  
  52. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement