stutrek / scrollmonitor

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

IsFullyEntered is triggered on DomContentLoaded for all items regardless of their state #94

Open Externaluse opened 4 years ago

Externaluse commented 4 years ago

Initialising a monitor on DomContentLoaded the state is correctly identified in stateChange. However, adding a callback for fullyEnterViewport is also triggered for each item. I would have expected that to fire only for items actually moving into the viewport. Illustrated here, with console output: https://jsfiddle.net/ExternalUse/17wL9pxv/9/

In entryChangeState, this produces correct results: `else if (this.isFullyInViewport):

guid1is correctly considered fully entered here guid2is correctly considered fully entered here for the fullyEnteredCallback function entryFullyEnterViewport() { console.log(this.watchItem.id + " may to be incorrectly considered fully entered, this.isFullyInViewport is " + this.isFullyInViewport); } this is produced: guid1 may to be incorrectly considered fully entered, this.isFullyInViewport is true guid2 may to be incorrectly considered fully entered, this.isFullyInViewport is false guid3 may to be incorrectly considered fully entered, this.isFullyInViewport is false guid4 may to be incorrectly considered fully entered, this.isFullyInViewport is false ` ...

It's also slightly weird that in stateChange, guid1 and 2 are caught by fullyEntered; in the fullyEntered callback only guid1 has isFullyInViewport == true.

Also, for the first element (guid1) the log message is produced twice.

I'm probably missing a trick, could you possibly help, please? Thank you very much.