hsnaydd/moveTo

Problem with request animation frame loop

Closed this issue · 1 comments

After encountering problems where the window simply wasn't scrolled, despite a correct call to the move function I started looking around in the code and found a problem in the request animation frame loop. Basically if the duration is too long but the scroll change is too little, the loop is exited after the first iteration because the window was scrolled less than half a pixel, therefore lastPageYOffset and currentPageYOffset remain the same.

A possible solution could be, to simply change this

if (lastPageYOffset && from === to) {
  if (
    lastPageYOffset === currentPageYOffset ||
    change > 0 && lastPageYOffset > currentPageYOffset ||
    change < 0 && lastPageYOffset < currentPageYOffset)
  {
    return options.callback(target);
  }
}

to this

if (currentPageYOffset === to) {
  return options.callback(target);
}

Now this might have unintended consequences I don't realize, but some form of check to see if the window actually scrolled to where it's supposed to could make sense.

cheers

Hi @genmacg
Thank you for the report. I examined the problem, yes you are right. I will deal with this issue.

Thank you