Filterable Slider with Pager
How it works
When you click a filter button, the code:
- Gets the slider's refresh ID from its
data-refresh-idattribute - Hides/shows slider items based on their
data-categoryattribute - Calls
refresh(sliderId)to update the pager and positions
Code Example
// Initialize the slider and get the API
const sliderAPI = slider();
// Filter items and refresh
function filterSlider(category) {
const sliderElement = document.querySelector('.slider');
const items = sliderElement.querySelectorAll('.slider-item');
items.forEach(item => {
if (category === 'all' || item.dataset.category === category) {
item.classList.remove('hidden');
} else {
item.classList.add('hidden');
}
});
// Call refresh to update the pager and scroll positions
sliderAPI.refresh(sliderId);
}