Skip to content

Instantly share code, notes, and snippets.

@anthonyshort
Created October 16, 2013 22:56
Show Gist options
  • Select an option

  • Save anthonyshort/7016437 to your computer and use it in GitHub Desktop.

Select an option

Save anthonyshort/7016437 to your computer and use it in GitHub Desktop.
slideshow.prototype.pauseOnHover = function(){
this.el.addEventListener('mouseover', this.pause.bind(this));
this.el.addEventListener('mouseout', this.play.bind(this));
}
slideshow.prototype.pause = function(){
this.paused = true;
}
slideshow.prototype.play = function(){
this.paused = false;
}
slideshow.prototype.auto = function(speed){
var self = this;
if( speed == null ) {
return this.speed !== 0; // Boolean, is it automatic?
}
this.speed = speed;
// clear any previous timeouts
if( this._timeout ) clearTimeout(this._timeout);
// This will keep firing until the speed is set to 0.
// If the slideshow is paused, the timeout will continue
// but it won't move to the next slide.
this._timeout = setTimeout(function tick(){
if(this.speed === 0) return; // No more automatic sliding
self._timeout = setTimeout(tick, speed); // Set it so we can clear it
if(this.paused === false) self.next(); // Next slide if not paused
}, speed);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment