Jump to content
Search Community

ScrollTrigger.matchMedia and prefers-reduced-motion

Digital Team test
Moderator Tag

Recommended Posts

Hi, does any one have any examples of a Timeline that uses ScrollTrigger.matchMedia and prefers-reduced-motion?

 

Im having an issue where i have multiple timelines on the page, but when reduced motion is toggled, the timeline its affecting seems to lose its position on the page and knock other timelines out of sync. I'm not changing any values of  the timeline yet, so seems to be related to the re-creation of the timeline. 

 

useEffect(() => {
    ScrollTrigger.matchMedia({
       "(min-width: 1024px)": function () {
        if(Timeline.current) Timeline.current.kill();
        SplashTween('desktop');
      },
      "(min-width: 1024px) and (prefers-reduced-motion: reduce)": function () {
        if(Timeline.current) Timeline.current.kill();
      	 // set true to tell tween to use reducedMotion
        SplashTween('desktop', true);
      }
    });

    return () => {
      if(Timeline.current) Timeline.current.kill();
    };

  }, []);

 

Link to comment
Share on other sites

Hi Zach,

thanks for the welcome, i will try put a demo together and come back. Its not the comma unfortunately, that was just a stripped back example done in the WYSIWYG. However I'm thinking i need to store the timelines styles/settings before allowing the reduced motion setting to override.

  

Link to comment
Share on other sites

  • 3 months later...

@Mista Ben, do you found a solution? I created a Codepen:

See the Pen RwpJOaP by vacoxudelpen (@vacoxudelpen) on CodePen

  • Per default the boxes are orange
  • For @media (prefers-reduced-motion: reduce) the boxes turn green
  • For @media (min-width: 1020px) and (prefers-reduced-motion: no-preference) the boxes turn red

The latter one is used within ScrollTrigger.matchMedia() to enable the animation. 

 

I testet it with the Windows 10 settings, as descripted here at MDN.

 

As expected, the red boxes get animated, the green ones not.

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