Created
October 16, 2013 22:56
-
-
Save anthonyshort/7016437 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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