Closed niklasp closed 8 months ago
Of course, not really a hack. Set a variable on progress like so:
function Example() {
const parallax = useParallax({
onProgressChange: (progress) => {
if (parallax.ref.current) {
// set progress to CSS variable
parallax.ref.current.style.setProperty(
"--progress",
progress.toString()
);
}
},
});
return (
<h1
ref={parallax.ref}
className="thing"
// use the progress to change the width of the border
style={{ WebkitTextStrokeWidth: `calc(20px * var(--progress))` }}
>
HELLO
</h1>
);
}
Here's a CodeSandbox to see it:
https://codesandbox.io/p/sandbox/react-scroll-parallax-text-stroke-klwy4l
Hope that helps.
I want to animate the textstroke of an element
or css variables on scroll. is that possible? how can i achieve it with some hack? e.g. get the progress of the parallax and then set it manually? any help appreciated