Jump to content

gallery slideshow pagination

Recommended Posts

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. 

image.thumb.png.c289cdd14bf27b55e26036714870e879.png

<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>

 

Link to comment
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. 

image.thumb.png.c289cdd14bf27b55e26036714870e879.png

<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?

Greeting, it's BeyondSpace, I am Squarespace dev focus on provide solutions to enhance feature that squarespace.com can't provide.
Feel free to check my current Squarespace Plugins Developement: Enable Pinch/Zoom on lightbox, Delivery Date Picker, Keyword Highlighter
If you find my answer fit your need, let's leave a like or upvote so others with the same issue can find their solution. Thank you

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

×
×
  • Create New...

Squarespace Webinars

Free online sessions where you’ll learn the basics and refine your Squarespace skills.

Hire a Designer

Stand out online with the help of an experienced designer or developer.