stickybits icon indicating copy to clipboard operation
stickybits copied to clipboard

State change callback

Open patric-eberle opened this issue 5 years ago • 6 comments

Is your feature request related to a problem? Please describe. We use your plugin in Vue and need to update the content of the sticky element, when it becomes sticky. As far as I understand the documentation, there is currently no callback method to execute functionality, when the element becomes or stops to be sticky.

Describe the solution you'd like There should be an option, to define a callback or bind to a custom event, to execute additional code, when the state of the sticky element changes (sticky/non-sticky).

Describe alternatives you've considered Did not find a good one.

Additional context In our case, we have a sidebar, that becomes sticky, once the header would cover it. In this case, some of the elements need to collapse by default in the sidebar, so it's size is reduced.

patric-eberle avatar Apr 17 '20 14:04 patric-eberle

Hey, thanks for filing an issue with Stickybits' first issue

github-actions[bot] avatar Apr 17 '20 14:04 github-actions[bot]

@patric-eberle, thanks for your thoughtful issue.

I thought about an event system before but I realized that would/could become a mess with multiple Stickybit items. Especially for maintenance, haha.

I think a callback that happened on a Stickybit state update could be clean enough. The inheriting code could run its own checks within the callback and make updates as necessary.

Thoughts?

yowainwright avatar Apr 18 '20 19:04 yowainwright

Yes I also think that a callback would be the better solution. In my opinion a relation to the instance may not be required but it should at least give the new state or have two events for becoming and leaving sticky mode. I don't think there is value in this. But with the callback we certainly could wire up the state change with the surrounding environment.

e.g.

stickybits("selector", {
  onChange(state) {}
});

patric-eberle avatar Apr 21 '20 10:04 patric-eberle

Ough, I need a callback handler before I can use this library, thought it was included out of the box tbh.

simplenotezy avatar Jun 22 '20 14:06 simplenotezy

I'm going to get to this repo asap. :pray:

I'm sure y'all understand trying to get extra work done during this time of adversity.

yowainwright avatar Jun 23 '20 18:06 yowainwright

My workaround is to use IntersectionObserveer and watch for the sticky classes

Sent with GitHawk

simplenotezy avatar Jun 24 '20 08:06 simplenotezy