// Get the slides
let slides = document.querySelectorAll('.uk-slider-items .tm-slide');
// Get the div where we will display the label
let sliderLabelDiv = document.getElementById('tm-slider-label');
// Function to update the text in the div
function updateSliderLabel(currentSlideIndex) {
// Format the label as "1 ----- 10"
let totalSlides = slides.length; // Get the total number of slides
let currentSlideNumber = currentSlideIndex + 1; // Get the current slide number (1-based)
let formattedLabel = `${currentSlideNumber} ----- ${totalSlides}`; // Create the formatted label
// Update the label text in the div
sliderLabelDiv.textContent = formattedLabel;
}
// Initialize with the first slide
updateSliderLabel(0); // Starts with the first slide
// Event handler for slide change
UIkit.util.on('.uk-slider-items', 'itemshown', function (event) {
let activeSlideIndex = Array.from(slides).indexOf(event.target); // Get the index of the active slide
updateSliderLabel(activeSlideIndex); // Update the label based on the active slide
});
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.