Codeinwp / Ideal-Image-Slider-JS

Quite simply the ideal Image Slider in vanilla JS.
http://idealimageslider.com
GNU General Public License v3.0
1.57k stars 160 forks source link

Slides stop after changing browser tabs #87

Open pmichna opened 7 years ago

pmichna commented 7 years ago

I'm using ideal image slider 1.5.1.

When I open my page, everything is fine. However, when I change browser tab, then go back to the tab with my page, the slides stop changing. There are no errors in the JS console. I checked the issue with Chrome and Firefox.

What could be the problem?

gfabrizi commented 7 years ago

Same here with chrome 55.0.2883.87 . Whenever the webpage lost focus (for example if i click on the browser developer's tools) the slider stops (the onStop event is fired). If i'll find out what the problem could be, i'd let you know...

gfabrizi commented 7 years ago

ok, i've found out a workaround... sorry, i don't know how to commit a change on github...

At line 412 after nextNavSelector: '', add this line stopOnBlur: true,

At line 650 change this

window.onblur = function() {
    this.stop();
}.bind(this);

to this:

if (this.settings.stopOnBlur) {
    window.onblur = function() {
        this.stop();
    }.bind(this);
}

USAGE Now if you want the slider to keep playing when you change the tab, initialize your slider with the option stopOnBlur set to false:

var slider = new IdealImageSlider.Slider({
       selector: '#sliderHP',
       stopOnBlur: false,
});