stutrek / scrollmonitor

A simple and fast API to monitor elements as you scroll
MIT License
3.3k stars 243 forks source link

Refreshing page and loading into the middle causes all the numbers to be wrong. #91

Closed mattkenefick closed 5 years ago

mattkenefick commented 5 years ago

I have a listener looking for { top: 0, bottom: -60 } which works just fine if the page loads all the way at scrollY = 0; but if you're half way down the page.. press refresh.. and Chrome puts you back there, all the numbers are wrong. It assumes the starting position is where you want to be, not the fact you're already half way down the page.

mattkenefick commented 5 years ago

Turns out this happens when you use "body" in the createContainer method. We were using a different container at first, but later changed to scrolling with the body. Instead of using scrollMonitor.create(...) we were using container.create(...) where the container = document.querySelector('body') from a flexibility standpoint.

This seemed to be the cause of the issues. Using scrollMonitor.create(...) for body scroll worked as expected.