Forked from shaddam/Add extra class of owl carousel first and last active item
Created
July 18, 2023 07:42
-
-
Save imuhammadshoaib/c8f46b91ca9da90b0bd3cc49caf87a5b to your computer and use it in GitHub Desktop.
Add extra class of owl carousel first and last active item
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var brandSlider = $('.brand-banner'); | |
brandSlider.owlCarousel({ | |
loop: false, | |
nav: false, | |
dots: false, | |
smartSpeed: 500, | |
margin: 0, | |
responsive: { | |
0: { | |
items: 1 | |
}, | |
340: { | |
items: 2 | |
}, | |
480: { | |
items: 3 | |
}, | |
768: { | |
items: 4 | |
}, | |
992: { | |
items: 4 | |
}, | |
1200: { | |
items: 5 | |
} | |
} | |
}) | |
function brandSliderClasses() { | |
brandSlider.each(function() { | |
var total = $(this).find('.owl-item.active').length; | |
$(this).find('.owl-item').removeClass('firstactiveitem'); | |
$(this).find('.owl-item').removeClass('lastactiveitem'); | |
$(this).find('.owl-item.active').each(function(index) { | |
if (index === 0) { | |
$(this).addClass('firstactiveitem') | |
} | |
if (index === total - 1 && total > 1) { | |
$(this).addClass('lastactiveitem') | |
} | |
}) | |
}) | |
} | |
brandSliderClasses(); | |
brandSlider.on('translated.owl.carousel', function(event) { | |
brandSliderClasses() | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment