How to make a sticky navbar change color when it has reached the top? Like in solidjs homepage
I think I should use this https://github.com/solidjs-community/solid-primitives/tree/main/packages/intersection-observer#readme , but I can't think of a way of implementing that. Code:
GitHub
solid-primitives/packages/intersection-observer at main · solidjs-c...
A library of high-quality primitives that extend SolidJS reactivity. - solid-primitives/packages/intersection-observer at main · solidjs-community/solid-primitives
4 Replies
The Intersection Observer API provides a way to asynchronously observe changes in the intersection of a target element with an ancestor element or with a top-level document's viewport.
Found an article which uses the Interesection Observer
https://css-tricks.com/how-to-detect-when-a-sticky-element-gets-pinned/
Would this help?
He uses top:-1px to trigger the observer here.
Chris Coyier
CSS-Tricks
How to Detect When a Sticky Element Gets Pinned | CSS-Tricks
Totally agree with David, on CSS needing a selector to know if a position: sticky; element is doing its sticky thing or not.
solid site uses an empty div instead which i think is cooler trick
https://playground.solidjs.com/anonymous/2a095e8f-313c-4c8c-ac64-07f192936646
It works! Thank you so much
I opted for another easier way but thank you anyway!