Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function scrollAnimated(to, duration) {
- var start = $(window).scrollTop(),
- change = to - start,
- currentTime = 0,
- increment = 20;
- function easeInOut(currentTime, startValue, change, duration) {
- currentTime /= duration / 2;
- if (currentTime < 1) {
- return change / 2 * currentTime * currentTime + startValue;
- }
- currentTime--;
- return -change / 2 * (currentTime * (currentTime - 2) - 1) + startValue;
- }
- function animateScroll() {
- currentTime += increment;
- var val = easeInOut(currentTime, start, change, duration);
- $(window).scrollTop(val);
- if (currentTime < duration) {
- setTimeout(animateScroll, increment);
- }
- }
- animateScroll();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement