Jump to content
Search Community

Animate pseudo-elements like `::before`

vanss472 test
Moderator Tag

Go to solution Solved by Rodrigo,

Recommended Posts

  • Solution

Hi,

 

The reason for that is the way you have your color string. This seems to work the way you expect:

.pinned-active {
  --pinned-active-black: rgba(14, 14, 14, 0);
}

Then in your JS:

sectionTl.current.to(section, {
  "--pinned-active-black": "rgba(14, 14, 14, 0.6)",
  y: () => -100,
  duration: 1,
  scrollTrigger: {
    ...
  }
});

Hopefully this helps.

Happy Tweening!

  • Like 1
Link to comment
Share on other sites

Hi,

 

Another option is to animate just the opacity, I just realize that the start and end colors are the same, so no need to run all that. This seems to work in the same way:

.pinned-active {
  --pinned-active-black: rgb(14, 14, 14);
  --active-opacity: 0;

  &::before {
    position: absolute;
    z-index: 100;
    display: flex;
    width: 100%;
    height: 100%;
    background-color: var(--pinned-active-black);
    opacity: var(--active-opacity);
    content: "";
    inset: 0;
  }
}

Then in the JS:

sectionTl.current.to(section, {
  "--active-opacity": 0.6,
  y: () => -100,
  duration: 1,
  scrollTrigger: {
    ...
  }
});

Hopefully this helps.

Happy Tweening!

  • Like 2
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...