Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possible to animate custom properties? #241

Closed
niklasp opened this issue Feb 21, 2024 · 1 comment
Closed

Is it possible to animate custom properties? #241

niklasp opened this issue Feb 21, 2024 · 1 comment
Labels

Comments

@niklasp
Copy link

niklasp commented Feb 21, 2024

I want to animate the textstroke of an element

-webkit-text-stroke: 
-text-stroke: 

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

@jscottsmith
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants