> All in One 586: How to Detect When a Sticky Element Gets Pinned

Ads

Monday, November 9, 2020

How to Detect When a Sticky Element Gets Pinned

Totally agree with David, on CSS needing a selector to know if a position: sticky; element is doing its sticky thing or not.

Ideally there would be a :stuck CSS directive we could use, but instead the best we can do is applying a CSS class when the element becomes sticky using a CSS trick and some JavaScript magic

I love it when there is a solution that isn’t some massive polyfill or something. In this case, a few lines of IntersectionObserver JavaScript and tricky usage of top: -1px in the CSS.

Direct Link to ArticlePermalink


The post How to Detect When a Sticky Element Gets Pinned appeared first on CSS-Tricks.

You can support CSS-Tricks by being an MVP Supporter.



from CSS-Tricks https://ift.tt/2GjffDD
via IFTTT

No comments:

Post a Comment

Partly Cloudy/Wind today!

With a high of F and a low of 21F. Currently, it's 36F and Clear/Wind outside. Current wind speeds: 25 from the Northwest Pollen: ...