Created
May 22, 2018 14:37
-
-
Save muzafferkoluman/9108370bb1496f89492cd69d983a21b0 to your computer and use it in GitHub Desktop.
smooth scroll effect
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
$(document).ready(function() { | |
//smooth scroll effect | |
$(function(){ | |
var $window = $(window); //Window object | |
var scrollTime = 1.2; //Scroll time | |
var scrollDistance = 500; //Distance. Use smaller value for shorter scroll and greater value for longer scroll | |
$window.on("mousewheel DOMMouseScroll", function(event){ | |
event.preventDefault(); | |
var delta = event.originalEvent.wheelDelta/120 || -event.originalEvent.detail/3; | |
var scrollTop = $window.scrollTop(); | |
var finalScroll = scrollTop - parseInt(delta*scrollDistance); | |
TweenMax.to($window, scrollTime, { | |
scrollTo : { y: finalScroll, autoKill:true }, | |
ease: Power1.easeOut, //For more easing functions see https://api.greensock.com/js/com/greensock/easing/package-detail.html | |
autoKill: true, | |
overwrite: 5 | |
}); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment