Spaces:
Sleeping
Sleeping
Download hooks/use-scroll-to.ts from 00Boobs00/InstantCoder: direct link, hf CLI and curl.
- Browser
- Download file 597 Bytes
-
https://huggingface.co/spaces/00Boobs00/InstantCoder/resolve/main/hooks/use-scroll-to.ts
- Command line
-
hf download hf://spaces/00Boobs00/InstantCoder/hooks/use-scroll-to.ts
-
curl -L -o use-scroll-to.ts https://huggingface.co/spaces/00Boobs00/InstantCoder/resolve/main/hooks/use-scroll-to.ts
597 Bytes
| import { animate, ValueAnimationTransition } from "framer-motion"; | |
| import { useRef } from "react"; | |
| export function useScrollTo() { | |
| let ref = useRef<HTMLDivElement>(null); | |
| function scrollTo(options: ValueAnimationTransition = {}) { | |
| if (!ref.current) return; | |
| let defaultOptions: ValueAnimationTransition = { | |
| type: "spring", | |
| bounce: 0, | |
| duration: 0.6, | |
| }; | |
| animate(window.scrollY, ref.current.offsetTop, { | |
| ...defaultOptions, | |
| ...options, | |
| onUpdate: (latest) => window.scrollTo({ top: latest }), | |
| }); | |
| } | |
| return [ref, scrollTo] as const; | |
| } | |