pref: colorful card

This commit is contained in:
Ou
2024-10-12 12:49:20 +08:00
parent 5d87ce3ea4
commit 698253e4ae
10 changed files with 109 additions and 42 deletions
+18
View File
@@ -0,0 +1,18 @@
import { useEffect, useRef, useState } from "react"
export function useSticky() {
const ref = useRef<HTMLDivElement>(null)
const [isSticky, setIsSticky] = useState(false)
useEffect(() => {
const observer = new IntersectionObserver(
([event]) => setIsSticky(event.intersectionRatio < 1),
{ threshold: [1], rootMargin: "-1px 0px 0px 0px" },
)
observer.observe(ref.current!)
return () => observer.disconnect()
}, [])
return { ref, isSticky }
}