etsted Posted March 29, 2014 Share Posted March 29, 2014 i got a little script i want to show: var scrollY = 0; var distance = 40; var speed = 24; function autoScrollTo(el) { var currentY = window.pageYOffset; var targetY = document.getElementById(el).offsetTop; var bodyHeight = document.body.offsetHeight; var yPos = currentY + window.innerHeight; var animator = setTimeout('autoScrollTo(''+el+'')',24); if(yPos > bodyHeight){ clearTimeout(animator); } else { if(currentY < targetY-distance){ scrollY = currentY+distance; window.scroll(0, scrollY); } else { clearTimeout(animator); } } } this is supposed to clear the "animator" if yPos is greater than bodyHeight, but woudnt yPos and bodyHeight have the same value? if not explain. Link to comment Share on other sites More sharing options...
Ingolme Posted March 29, 2014 Share Posted March 29, 2014 Checking that it's greater makes sure that if it somehow skips the exact bodyHeight value and has something larger the program will still stop the animation. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now