Created
January 7, 2024 16:04
-
-
Save josephturnerjr/7f3dda0bba9140ff3bdcba80b2041770 to your computer and use it in GitHub Desktop.
Script for disabling the left/right Bootstrap carousel controls at the first/last slide
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
<!-- Script for disabling the left/right Bootstrap carousel controls at the first/last slide --> | |
(function() { | |
const removeClass = function(selector, className) { | |
Array.from(document.querySelectorAll(selector)).forEach(function(el) { | |
el.classList.remove(className); | |
}); | |
}; | |
const addClass = function(selector, className) { | |
Array.from(document.querySelectorAll(selector)).forEach(function(el) { | |
el.classList.add(className); | |
}); | |
}; | |
let car = document.querySelector('#myCarousel'); | |
car.addEventListener('slide.bs.carousel', function(e) { | |
removeClass('.carousel-control-prev', 'd-none'); | |
removeClass('.carousel-control-next', 'd-none'); | |
if(e.to == 0) { | |
addClass('.carousel-control-prev', 'd-none'); | |
} else { | |
if (e.to == 4) { | |
addClass('.carousel-control-next', 'd-none'); | |
} | |
} | |
}); | |
addClass('.carousel-control-prev', 'd-none'); | |
})(); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment