Adding a slide counter to GLightbox #362
gingerchew
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
This isn't a 100% sanctioned by the GLightbox staff answer, but its one that I use often and I know it is something a lot of people ask how to do so I figured I'd share. This is given AS IS, meaning if it doesn't work, I'm not really able to support you with it. It's made to work with GLightbox 3.2.0, but you will probably have luck with all of v3.
I'll do a small write up of how it works, but the CodePen is here if you want the TL;DR.
Problem: Modal needs a slide counter.
Solution: Add a slide counter.
Steps:
With those in mind this is how I went about it:
Setup done, lets write our functions. We are ultimately doing 3 things; inserting, updating, removing. Let's set up when we want these functions to run.
These are the general events that will work for now, but I want to control these with a little bit more flexibility. I'm going to write an function to handle the different events in one place.
Now let's write the individual functions that will do the actual work.
Then with just a bit of CSS
Our counter updates on each slide change and on open.
You can checkout the full codepen here.
A final note
close
eventFor true compatibility, the
removeCounter
function would need to run on not just the button click event but also on the escape key press event, or on any other close modal method. The reason for using that instead of theclose
event is to prevent the counter from lagging behind after the modal has already transitioned out. Using the click and keypress events lets us remove it from the DOM outright.Beta Was this translation helpful? Give feedback.
All reactions