locomotivemtl / locomotive-scroll

🛤 Detection of elements in viewport & smooth scrolling with parallax.
https://locomotivemtl.github.io/locomotive-scroll
MIT License
7.55k stars 1.11k forks source link

Fix infinite looping bug #469

Open jeff-wolff opened 1 year ago

jeff-wolff commented 1 year ago

Hello 👋 timeSinceStart incorrectly calculated in the script as this.startScrollTs is undefined. preventing checkScroll() from initiating stopScrolling()

Steps to reproduce the behavior:

  1. Scroll away and press "Home" on your keyboard
  2. Observe the loop not stopping the transform function

Fixed by changing this line: timeSinceStart = Date.now() - this.startScrollTs;

to

timeSinceStart = Date.now() - this.startScrollTs ? this.startScrollTs : Date.now();

There might be a better way to initialize this.startScrollTs?

Dushyant1295 commented 1 year ago

@devenini @Jerek0

RafaelKr commented 1 year ago

Wouldn't it be better to write this? const timeSinceStart = this.startScrollTs ? Date.now() - this.startScrollTs : 0;