somewebmedia / hc-sticky

JavaScript library that makes any element on your page visible while you scroll.
https://somewebmedia.github.io/hc-sticky/
MIT License
462 stars 114 forks source link

Add check to onscroll functionality to ensure element is visible #10

Closed alexcason closed 10 years ago

alexcason commented 10 years ago

The scroll event is triggered for all instances of hcSticky on the page, even if they're not visible. This was causing a bug where, after scrolling, the hcSticky element which was hidden would snap to the top of the page with fixed positioning. The bug is demonstrated in the following gif:

hc-sticky-bug

I have added a check to the onscroll functionality to ensure that the element is visible before continuing. This resolves the bug demonstrated above.