NOW fixed bug that prevented smoothScroll from working
This commit is contained in:
parent
07fc92369c
commit
b6b7a21c76
@ -13,7 +13,7 @@ function smoothScroll(targetId){
|
|||||||
targetHeight = target.offsetTop; //get its height
|
targetHeight = target.offsetTop; //get its height
|
||||||
currentHeight = getScrollY(); //grab the current scroll position
|
currentHeight = getScrollY(); //grab the current scroll position
|
||||||
prevHeight = null;
|
prevHeight = null;
|
||||||
startTime = performance.now(); //we have to reset the start time every time the animation runs
|
startTime = null; //we have to reset the start time every time the animation runs
|
||||||
if (currentHeight != targetHeight) {
|
if (currentHeight != targetHeight) {
|
||||||
window.requestAnimationFrame(animateScroll);//schedule the animation
|
window.requestAnimationFrame(animateScroll);//schedule the animation
|
||||||
}
|
}
|
||||||
@ -27,7 +27,7 @@ function animateScroll(timeStamp){
|
|||||||
var deltaScroll = deltaStep * offsetScroll; //decide how far to scroll this tick
|
var deltaScroll = deltaStep * offsetScroll; //decide how far to scroll this tick
|
||||||
window.scroll(0, currentHeight + deltaScroll); //scroll!
|
window.scroll(0, currentHeight + deltaScroll); //scroll!
|
||||||
currentHeight = getScrollY();//re-record the current height after scrolling for comparison
|
currentHeight = getScrollY();//re-record the current height after scrolling for comparison
|
||||||
if((currentHeight != targetHeight) && (currentHeight != prevHeight)){ //schedule another tick until we get where we're going or we get as far as we can
|
if ((currentHeight != targetHeight) && ((currentHeight != prevHeight) || (deltaStep == 0))) { //schedule another tick until we get where we're going or we get as far as we can. deltastep will always be 0 on the first frame.
|
||||||
window.requestAnimationFrame(animateScroll);
|
window.requestAnimationFrame(animateScroll);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user