Last active
August 29, 2015 14:09
-
-
Save prisme/0678562c4af604e0ac2d 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
| /* | |
| * | |
| * Works with numbers or elements (not jquery objects) | |
| * | |
| * scrollTo(100); | |
| * scrollTo(element); | |
| * | |
| * Update 'scroller' variable with custom scrolling element if not document.body | |
| * | |
| */ | |
| define([ | |
| 'gsap' | |
| ], function() { | |
| var dummy = document.createElement('div'); | |
| var scroller = document.body; | |
| var distance = 0; | |
| return function(element) { | |
| distance = typeof element == 'object' ? element.offsetTop : element; | |
| TweenLite.set(dummy, {x: scroller.scrollTop }); | |
| TweenLite.to(dummy, Math.abs(distance - scroller.scrollTop) / 1000, {x: distance, ease: Power1.easeInOut, onUpdate: function() { | |
| scroller.scrollTop = parseInt(dummy._gsTransform.x); | |
| }}); | |
| } | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment