harm-less / angular-sticky

Pure javascript AngularJS directive to make elements stick when scrolling
http://harm-less.github.io/angular-sticky
83 stars 38 forks source link

stickyness of all elements is lost, if one element gets destroyed #11

Closed LordMidi closed 8 years ago

LordMidi commented 8 years ago

We have several sticky elements. Some of them are included in view of states from the ui-router. So if there is a state change, the destroy function of the sticky elements which are not available anymore is fired. But here the stickyness of all elements gets removed, even those which should stay sticky.

You should only destroy the 'hlSticky' Directive which fires the destroy function, not ALL!

$scope.$on('$destroy', function onDestroy() { stickyElementCollection.destroy(); });

harm-less commented 8 years ago

That's a good point. I'll mark it as a bug and fix it right away. I'll notify you when I made a new patch.

harm-less commented 8 years ago

I fixed it, here you go. Thanks for spotting this.

LordMidi commented 8 years ago

Thx for your efforts. I've updated to 0.2.2 but in my case if (!stickyElementCollection.trackedElements.length) { always validated to true (stickyElementCollection.trackedElements.length is always 0) so there is no change in the behaviour.

harm-less commented 8 years ago

Well, that's embarrassing... Please update to `0.2.3`` and see if that works.

I forgot trackedElements was a function and needed to be called as such.

LordMidi commented 8 years ago

Nice. It works. Many thanks for your instant help!

(just one note - maybe you want to switch to 2 spaces instead of tabs for indent. I think it's more common these days)

see ya

harm-less commented 8 years ago

You're welcome, thanks for the issue report again.

The age old indent war, haha. Even though it might be more popular, I feel with a bit more indentation it's easier to read. So that's why I decided to stick with that. But one advantage of tabs is that you can tell your IDE how to interpret a tab. So if you prefer 2 spaces, you can simply pretend ;)