Skip to content

Instantly share code, notes, and snippets.

@prisme
Last active August 29, 2015 14:09
Show Gist options
  • Select an option

  • Save prisme/0678562c4af604e0ac2d to your computer and use it in GitHub Desktop.

Select an option

Save prisme/0678562c4af604e0ac2d to your computer and use it in GitHub Desktop.
/*
*
* 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