Last active
January 12, 2017 14:44
-
-
Save Kelderic/172c70fbd03c759d689c35bbaac09857 to your computer and use it in GitHub Desktop.
This is an element prototype that animates the element's horizontal scroll. By default, it scrolls the element all the way over to the right, and if an integer is passed in, it animates until the element's scrollLeft property equals that integer.
This file contains 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
HTMLElement.prototype.scrollHorizontally = function( newScrollLeft ) { | |
var self = this; | |
newScrollLeft = newScrollLeft ? newScrollOffset : self.scrollWidth - self.offsetWidth | |
animate(); | |
function animate(){ | |
if ( self.scrollLeft < ( newScrollLeft ) ) { | |
self.scrollLeft = self.scrollLeft + 10; | |
window.requestAnimationFrame(animate); | |
} | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment