Created
October 25, 2012 16:22
-
-
Save jnf/3953800 to your computer and use it in GitHub Desktop.
Extending ZeptoScroll (https://github.com/suprMax/ZeptoScroll) to support horizontal and vertical scrolling.
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
;(function($) { | |
var interpolate = function (source, target, shift) { | |
return (source + (target - source) * shift); | |
}; | |
var easing = function (position) { | |
return (-Math.cos(position * Math.PI) / 2) + .5; | |
}; | |
$.scrollBoth = function(XY, duration, easingF) { | |
var endX = XY[0], endY = XY[1]; | |
duration = duration || 200; | |
(typeof easingF === 'function') && (easing = easingF); | |
var startY = window.pageYOffset, startX = window.pageXOffset, | |
startT = Date.now(), finishT = startT + duration; | |
var animate = function() { | |
var now = +(new Date()), shift = (now > finishT) ? 1 : (now - startT) / duration; | |
window.scrollTo(interpolate(startX, endX, easing(shift)), interpolate(startY, endY, easing(shift))); | |
(now > finishT) || setTimeout(animate, 15); | |
}; | |
animate(); | |
}; | |
}(Zepto)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment