Stuart Nelson
Stuart Nelson

Reputation: 307

On clicking element restart Glide.js

I have a lightbox with a glide slider in it. Glide.js is already initiated. I want on clicking my specified element to re-start the slider. When closing the lightbox I'd like to pause the slider. I can see that this is possible with the API but cant get it to work...

My slider setup

var slider_alt=$("#glide--alt").glide({
    type:"slideshow",
    autoplay:2500, 
    animationDuration:2000,
    hoverpause:false
}),
slider_api=slider_alt.data("glide_api");

My jQuery for trying to restart the slider

popUp_openButton.click(function(){
    slider_alt.jump(1);
    slider_alt.play();
});

popUp_closeButton.click(function(){ 
    slider_alt.pause();
}); 

Upvotes: 1

Views: 2547

Answers (2)

Stuart Nelson
Stuart Nelson

Reputation: 307

Heres my final working code. On opening the modal window the slider is recalculated and starts at slide 1. On closing its stops clearing all objects and bindings.

//Setting up slider
var slider_alt=$("#glide--alt").glide({
    type:"slideshow",
    autoplay:2500, 
    animationDuration:2000,
    hoverpause:false
}),
slider_alt_api=slider_alt.data("glide_api");


var popUp_openButton    = $('.popUp__button--open'),
popUp_closeButton   = $('.popUp__button--close');

popUp_openButton.click(function(){
    slider_alt_api.refresh();
    slider_alt_api.jump('=1');
});

popUp_closeButton.click(function(){ 
    slider_alt_api.destroy();
});     

$(document).keyup(function(e){
    if(e.keyCode === 27) {
        slider_alt_api.destroy();
    }  
}); 

Upvotes: 1

Sree
Sree

Reputation: 556

Use .refresh():

popUp_closeButton.click(function(){ 
   slider_alt.refresh();
});

Upvotes: 1

Related Questions