Jump to content
Search Community

DOMException: Failed to read the 'cssRules' property from 'CSSStyleSheet': Cannot access rules

Separator test
Moderator Tag

Recommended Posts

Hi there,

Im trying to animate a pseudo element in my React (Nextjs) app but i get an error using CSSRulePlugin.

 

I import the plugin like this: 

import { CSSRulePlugin } from "gsap/dist/CSSRulePlugin";

and then trying to use it like this:

 

gsap.registerPlugin(CSSRulePlugin);
    let checkboxRipple = CSSRulePlugin.getRule(
      `.checkbox-wrapper #${[id]}:after`
    );
    gsap.to(checkboxRipple, {
      cssRule: {
        scale: 1.75,
        opacity: 0,
      },
      duration: 2,
    });
 

but i get the error you see in the attached screenshot.

Any help?

Screenshot 2022-06-18 at 02.23.08.png

Link to comment
Share on other sites

Yep, it looks like your rule is malformed or something - I believe it's returning undefined. And like @PointC said, we almost always recommend using CSS variables instead now since pretty much every major browser supports that feature natively. That's stated in the CSSRulePlugin docs as well. In general, I think it's a cleaner option personally. 👍 

  • Like 1
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...