vue-sticky-directive icon indicating copy to clipboard operation
vue-sticky-directive copied to clipboard

Element(s) slightly jumping when sticked

Open b44rd opened this issue 6 years ago • 7 comments

Hi, and thanks a lot for making this sweet directive!

I do, however notice that there is a subtile "jump" when activating/deactivating stickyness. I´m using Google Chrome, and the "jump" behaviour is reproducable in the demo/example as well.

Not 100% sure how to fix the issue yet, but it seems like the activate/deactivate of the stickyness do not listen to the scroll event in an optimal way somehow, as it seems like the placement of the placeholder happens too late some times.

b44rd avatar Jun 11 '19 06:06 b44rd

I'm also dealing with this problem on a test project =(

brunosfreitas avatar Jul 24 '19 19:07 brunosfreitas

I found this problem appears for me in bottom sticky situations. The sticky element recalculates using current element height, which in my case changed. This causes a cascade of jumps in the differential between the original and sticky heights.

To resolve, I pulled the source directive into my project and latched the height while the element is stuck (in recomputeState):

this.state = Object.assign({}, this.state, { height: this.lastState.sticked ? this.state.height : this.getHeight(), width: this.getWidth(), xOffset: this.getXOffset(), placeholderElRect: this.getPlaceholderElRect(), containerElRect: this.getContainerElRect() });

This is valid for the majority of use cases, however, if someone is using the with consistently sized elements and relies on this during resizes, this would be a breaking change. I would argue resize is a different event and should follow a different execution path, and likely needs a functional change to reset stickiness on resize.

I entered a pull request to demonstrate what I did, and can discuss further adjustments there.

rleeson avatar Jul 26 '19 18:07 rleeson

I found this problem appears for me in bottom sticky situations. The sticky element recalculates using current element height, which in my case changed. This causes a cascade of jumps in the differential between the original and sticky heights.

Have your tried wrap your sticky element into a constant height wrapper? The wrapper remain the constant size but the content may vary as you need.

mehwww avatar Jul 27 '19 12:07 mehwww

I have the same issue, but it seems as though the demo has it fixed; atleast I can't reproduce it from the demo. See gif:

vue sticky

simplenotezy avatar Apr 16 '20 12:04 simplenotezy

@simplenotezy Recently implemented the exact same layout as you reference here, using position: sticky. It ended up quite well, but it is a matter of browser support; https://caniuse.com/#feat=css-sticky

b44rd avatar Apr 16 '20 12:04 b44rd

I noticed the bug I showed in the gif didn't happen on my laptops smaller screen only my second display. Anyhow I'm using chrome so don't thibk browser support is an issue

Sent with GitHawk

simplenotezy avatar Apr 17 '20 23:04 simplenotezy

@simplenotezy Did you solve the problem? Unfortunately, in my project I also have it :(

dscbirio avatar Nov 16 '20 07:11 dscbirio