1

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();
}); 
Jędrzej Chałubek
  • 1,410
  • 1
  • 16
  • 29
Stuart Nelson
  • 307
  • 2
  • 13

2 Answers2

1

Use .refresh():

popUp_closeButton.click(function(){ 
   slider_alt.refresh();
});
Anders
  • 8,307
  • 9
  • 56
  • 88
Sree
  • 516
  • 1
  • 7
  • 23
1

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();
    }  
}); 
Stuart Nelson
  • 307
  • 2
  • 13