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

are there any hooks for stick unstick ? #4

Closed mkoczorowski closed 8 years ago

mkoczorowski commented 8 years ago

I would like to hook to stick 'event'? and prepend my DOM to body. Is this possible ?

harm-less commented 8 years ago

I'm not quite sure what you mean. Do you mean you would like to bind a method to the directive that fires whenever the element becomes sticky or unsticky?

And what do you mean by prepending your DOM to the body?

mkoczorowski commented 8 years ago

Hi thanks for the reply. When I set up an element using hl-sticky directive. Its gets a position: fixed when sticks. This is fine but
what I would also to do is to move it and prepend it to body element when this happens. I need some kind of hook on event being fired whenever the element sticks or unsticks. I hope its clear.

mkoczorowski commented 8 years ago

Would be nice to have hooks onStick=""" onUnstick="" kind of things. Is this achievable ?

harm-less commented 8 years ago

I like the hook that fires a binded method when it becomes sticky or unsticky. I think I'd like to call the attribute sticky-event and that fires a method when anything noteworthy happens in the directive. Within the method you can check whether the expected event was fired.

For example:

<div hl-sticky sticky-event="stickyEvent(event)">
$scope.stickyEvent = function(event) {
  if (event.event === 'sticky-start') {
    ... do something
  }
  else if (event.event === 'sticky-end') {
    ... do something
  }
}

What do you think of this proposal?

I still don't understand what you mean with "prepend to the body". Or has this request been answered with the above proposal?

mkoczorowski commented 8 years ago

I like it very much! Would be great. By "prepend to the body" I mean $element.prependTo($('body')). - little hack I need to do to make it work inside Semantic UI sidebar (ui components used in my project). Due to how css is structured there, even if element gets a 'fixed' position it still scrolls with content. I have to take it out of this container and append to body. stickyEvent would work perfect for this case as well as for any other giving developers an option to act on the behaviour. Thanks for your help :-) great work

harm-less commented 8 years ago

I haven't seen this prepend to body behavior with any sticky plugin I encountered. And from their plugin page, it seems to work without doing that at all.

But I'll at least add this event mechanism in a future release.

mkoczorowski commented 8 years ago

Hey! To be honest your implementation is way better!

harm-less commented 8 years ago

I've added the feature and I've created a prerelease for this (0.1.1-0). I've also create a demo page so you can see it's functionality in all detail. You can also refer to the API documentation, but I think the demo is easier to understand.

Let me know how it went with your implementation in Semantic UI!