w11k / angular-sticky-things

Sticky Directive for Angular 2+

Home Page:https://w11k.github.io/angular-sticky-things

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Upgrading to 1.1.9 breaks due to "Cannot read property 'offsetTop' of undefined".

jamesofficer opened this issue · comments

Hey there,

We've been using StickyThings in our app for a little while, and it was working great. However with the recent upgrade from 1.1.2 to 1.1.9, I get the following error and the sticky no longer works:

Screen Shot 2019-10-28 at 4 23 35 pm

I noticed if I have the scrollContainer property set then that error disappears, however the sticky no longer works. I've put the class="scroll-container" in a bunch of places but to no avail.

Going by the documentation a scroll container shouldn't be required (it wasn't for 1.1.2)? Any help would be great. Thanks for your hard work!

I came across this issue as well with the update.

Need to check that this.boundaryElement exists before attempting to access property this.boundaryElement.offsetTop to prevent Cannot read property 'offsetTop' of undefined error.

const reachedUpperEdge = window.pageYOffset < (this.boundaryElement.offsetTop - marginTop);

Great project!

I did manage to make it work again by setting a boundary element, however I still got the same error message. Not sure if it is because I have some *ngIf statements on some of the elements though. Hopefully we get a fix soon 🤞.

@ramtennae @yahmez00 thanks for the hint and for using our library. i've fixed the issue. will release a new version later tomorrow.

@ramtennae @yahmez00 published new version 1.2.1 - should fix the problem.

1.2.1 fixed it, thanks!

But now observe some other issue - marginTop works in a different way: it catches sticky header good on scroll down. But then if I scroll up - my sticky element disappear only if scroll till parent top (scrollTop ==0) but not at position when it became sticky on scroll down
sticky_issue

Pay attention when i scroll up - header disappears too late - when I have scrolled on top