Fix bug preventing scroll animation from running
This commit is contained in:
parent
9f82dd214c
commit
07fc92369c
@ -7,16 +7,14 @@ var targetHeight = null;
|
|||||||
var prevHeight = null;
|
var prevHeight = null;
|
||||||
var currentHeight = null;
|
var currentHeight = null;
|
||||||
var startTime = null;
|
var startTime = null;
|
||||||
var count = 0;
|
|
||||||
/* does some basic checking then calls animate() to do the heavy lifting */
|
/* does some basic checking then calls animate() to do the heavy lifting */
|
||||||
function smoothScroll(targetId){
|
function smoothScroll(targetId){
|
||||||
target = document.getElementById(targetId);//grab the element
|
target = document.getElementById(targetId);//grab the element
|
||||||
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 = null; //we have to reset the start time every time the animation runs
|
startTime = performance.now(); //we have to reset the start time every time the animation runs
|
||||||
if(currentHeight != targetHeight){
|
if(currentHeight != targetHeight){
|
||||||
count = 0;
|
|
||||||
window.requestAnimationFrame(animateScroll);//schedule the animation
|
window.requestAnimationFrame(animateScroll);//schedule the animation
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user