Forked from shaddam/Add extra class of owl carousel first and last active item
Created
July 2, 2019 10:56
-
-
Save akshuvo/87d4c8dfa5ce99684325f90e2c45964d to your computer and use it in GitHub Desktop.
Add extra class of owl carousel first and last active item
This file contains hidden or 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