Skip to content

Problem with request animation frame loop #8

Closed
@davidmondok

Description

@davidmondok

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions