Custom jquery code not working inside the popup box #438
-
Hello, I have a list inside the popup box, and I have some custom js code added. I am using the inline element (text content inside the popup box). The code will loop through all the list items and add the classname 'active' to one of the item every 4 seconds. The HTML list inside the popup:
my jquery code::
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
It sounds like you're using the inline slide. The thing to remember about how GLightbox works, the HTML that is being used for inline slides isn't used. It is copied. When you open the lightbox, it copies that HTML and inserts that into the slide. There are a few solutions to this problem, the one I would suggest is using the events that are offered by GLightbox. const lightbox = GLightbox();
lightbox.on('slide_load', () => {
// set up your cycle function loop
}) Since we're only running the function after the lightbox is open and loaded, your snippet will see the items in the slide. Things to look out for:
let intervalHandle = null;
lightbox.on('slide_load', () => {
if (intervalHandle !== null) {
clearInterval(intervalHandle);
intervalHandle = null;
}
intervalHandle = setInterval(/* ... */);
});
lightbox.on('close', () => clearInterval(intervalHandle)); This prevents memory leaks from happening. |
Beta Was this translation helpful? Give feedback.
It sounds like you're using the inline slide. The thing to remember about how GLightbox works, the HTML that is being used for inline slides isn't used. It is copied.
So when the page loads and you use
$('.test-list-1 li')
it only sees the one on the page.When you open the lightbox, it copies that HTML and inserts that into the slide.
There are a few solutions to this problem, the one I would suggest is using the events that are offered by GLightbox.
Since we're only running the function after the lightbox is open and loaded, your snippet will see the items in the slide.
Things to loo…