LFyel101 Posted November 3, 2021 Share Posted November 3, 2021 Trying to create a counter for my slideshow gallery which changes number in relation to what image the slideshow is currently on. Initially had it working by creating a counter that changes when the arrows are clicked, but sometimes you can click the page and the image will not change (however the counter which detects the clicks will!) I wondered if anyone had any luck creating gallery pagination by getting the index of the image currently on display, however this level of javascript is a bit over my head. Any help would be greatly appreciated! If anyone had any plug ins to recommend rather than my own shonky javascript that would be greatly appreciated! I've created the counter by adding a code block below the image and inserting the following script. <p class="counter"></p> <script> let imageNumber = 1 const counter = document.querySelector("p.counter") const nextButton = document.querySelector("a.next") const prevButton = document.querySelector("a.previous") const image = document.querySelectorAll(".thumb-image").length const galleryContainer = document.querySelector(".sqs-block-gallery") const imageSingle = document.querySelector(".thumb-image") let newCurrent = imageSingle.tabIndex const updateSection = function (){ counter.innerHTML = `${imageNumber} / ${image}` } const nextFunction = function (){ imageNumber = imageNumber + 1 if ( imageNumber > image ) { imageNumber = 1 } } const prevFunction = function (){ imageNumber = imageNumber - 1 if ( imageNumber < 1 ) { imageNumber = image } } updateSection() nextButton.addEventListener("click", function (){ nextFunction() updateSection() }) imageSingle.addEventListener("click", function (){ nextFunction() updateSection() }) prevButton.addEventListener("click", function (){ prevFunction() updateSection() }) </script> Beyondspace 1 Link to comment
Beyondspace Posted November 9, 2021 Share Posted November 9, 2021 On 11/3/2021 at 11:57 PM, LFyel101 said: Trying to create a counter for my slideshow gallery which changes number in relation to what image the slideshow is currently on. Initially had it working by creating a counter that changes when the arrows are clicked, but sometimes you can click the page and the image will not change (however the counter which detects the clicks will!) I wondered if anyone had any luck creating gallery pagination by getting the index of the image currently on display, however this level of javascript is a bit over my head. Any help would be greatly appreciated! If anyone had any plug ins to recommend rather than my own shonky javascript that would be greatly appreciated! I've created the counter by adding a code block below the image and inserting the following script. <p class="counter"></p> <script> let imageNumber = 1 const counter = document.querySelector("p.counter") const nextButton = document.querySelector("a.next") const prevButton = document.querySelector("a.previous") const image = document.querySelectorAll(".thumb-image").length const galleryContainer = document.querySelector(".sqs-block-gallery") const imageSingle = document.querySelector(".thumb-image") let newCurrent = imageSingle.tabIndex const updateSection = function (){ counter.innerHTML = `${imageNumber} / ${image}` } const nextFunction = function (){ imageNumber = imageNumber + 1 if ( imageNumber > image ) { imageNumber = 1 } } const prevFunction = function (){ imageNumber = imageNumber - 1 if ( imageNumber < 1 ) { imageNumber = image } } updateSection() nextButton.addEventListener("click", function (){ nextFunction() updateSection() }) imageSingle.addEventListener("click", function (){ nextFunction() updateSection() }) prevButton.addEventListener("click", function (){ prevFunction() updateSection() }) </script> What is your site url? BeyondSpace - Squarespace Website Developer 🖼️ Lightbox Studio (Enable Pinch/Zoom on lightbox, video lightbox and much more) 🗓️ Delivery Date Picker (Squarespace Date picker form field) 💫 Gallery block 7.1 workaround 🥳 No-code customisations for Squarespace (+100 Spark plugin customisations) 🥳 Freemium Squarespace Widget Templates (+1000 Elfsight Templates) If you find my answer useful, let's leave a like or upvote so others with the same issue can find their solution. Thank you! Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment