Advanced Examples β
Custom Timing β
Slower interval with a fast transition:
javascript
ContinuousCarousel('myCarousel', {
interval: 4000,
transitionDuration: 500
});Custom Easing β
Use any CSS transition-timing-function for the slide animation:
javascript
ContinuousCarousel('myCarousel', {
easing: 'linear'
});
ContinuousCarousel('myCarousel', {
easing: 'cubic-bezier(0.4, 0, 0.2, 1)'
});Callbacks β
Hook into carousel events. onSlideChange fires when a slide begins transitioning; onSlideEnd fires once the animation completes:
Callback events will appear hereβ¦
javascript
const log = document.getElementById('callbackLog');
const addEvent = (text) => {
const li = document.createElement('li');
li.textContent = text;
log.prepend(li);
};
const carousel = ContinuousCarousel('myCarousel', {
interval: 3500,
onSlideChange: (index) => addEvent(`onSlideChange β slide ${index}`),
onSlideEnd: (index) => addEvent(`onSlideEnd β slide ${index}`),
onPause: () => addEvent('onPause'),
onPlay: () => addEvent('onPlay'),
onDestroy: () => addEvent('onDestroy'),
});Programmatic Control β
Use the API to control playback and navigation:
javascript
const carousel = ContinuousCarousel('myCarousel', {
autoplay: false
});
document.getElementById('playBtn').addEventListener('click', () => {
carousel.play();
});
document.getElementById('pauseBtn').addEventListener('click', () => {
carousel.pause();
});
// Jump to a specific slide (0-based index)
document.getElementById('slide3Btn').addEventListener('click', () => {
carousel.goToSlide(2);
});
document.getElementById('destroyBtn').addEventListener('click', () => {
carousel.destroy();
});Dynamic Configuration β
Update settings on a running carousel:
javascript
const carousel = ContinuousCarousel('myCarousel', {
interval: 2000
});
// Speed up
carousel.updateConfig({ interval: 500 });
// Slow down
carousel.updateConfig({ interval: 5000 });Keyboard Navigation β
Tab to the carousel and use arrow keys to advance slides. Press Space or Enter to toggle pause.
javascript
ContinuousCarousel('myCarousel', {
keyboardNav: true // enabled by default
});TIP
Click the carousel above, then use Arrow Right to advance or Space to pause.