Jump to content
Search Community

Text Color Change (blend-mode effect)

coldgroove test
Moderator Tag

Recommended Posts

 

Hey there uhm, I'm trying to make a similar effect but got stuck so maybe you guys can help me?

I've basically copied @PointC 's svg pattern with the mask one not the clipPath, and I only want to have a vertical mask with 2 fixed colors changing into each other. So I only changed the svg size to be width=100% height=100% just to make it a fullscreen one. There is no probs there.

 

However why do you select the rect's that are inside of definition tags for x and y animations? I got confused about that because if I select those my mask doesn't change neither with scaleY: 0, or height:0. 

Nonetheless if I attach my ref to the rect that you defined as "this is the fixed color background with white as the fill, but the stroke changes", it works. I mean it's kinda. The blueScreen is going upwards with scaleY: 0. But the mask doesnt work so the other text isn't showing up for some reason. I've removed the stroke stuff too if its related.

 

This is my svg el with a few changes:

<svg
id="maskDemo"
xmlns="http://www.w3.org/2000/svg"
width="100%"
height="100%"
viewBox="0 0 400 200"
>
  <title>Invert SVG text fill color with masks</title>
  <defs>
      <mask id="theMask">
        <rect
        id="maskerH"
        width="400"
        height="200"
        x="-400"
        y="0"
        fill="#fff"
        />
        <rect
        id="maskerV"
        width="400"
        height="200"
        x="0"
        y="200"
        fill="#fff"
        />
      </mask>
  </defs>
{/* <!-- this is the fixed color background with white as the fill, but the stroke changes --> */}
  <rect
  id="bgFixed"
  ref={blueScreenRef}
  width="400"
  height="200"
  fill={data.textColorCode}
  // stroke="#94c356"
  // stroke-width="4"
  />

    {/* <!-- this text color changes based on the chosen color swatch--> */}
  <g id="startColor" fill={data.bgColorCode} fontSize="100">
    <text className="theCount" textAnchor="end" x="220" y="140">
      100
  </text>
  <text textAnchor="start" x="230" y="140">
    %
    </text>
  </g>

  <g mask="url(#theMask)">
    {/* <!-- this is the changeable color background based on the swatch click--> */}
  <rect id="bgChange" width="400" height="200" fill="#94c356"  />

    {/* <!-- this is the duplicate text group revealed by the masks it's always white --> */}
  <g id="end" fill="white" fontSize="100">
    <text className="theCount" textAnchor="end" x="220" y="140">
      100
  </text>
  <text textAnchor="start" x="230" y="140">
    %
    </text>
  </g>
  </g>
  </svg>

and this is my useEffect:

useEffect(() => {
    const ctx = gsap.context(() => {
      const sharedScrollTrigger = {
        start: "top top",
        trigger: sectionRef.current,
        invalidateOnRefresh: false,
        scrub: 1,
        end: () => "+=4500",
        // markers: true,
      };
      // pinning the section
      gsap.to(sectionRef.current, {
        scrollTrigger: {
          start: "top top",
          pin: true,
          trigger: sectionRef.current,
          invalidateOnRefresh: false,
          scrub: 1,
          end: () => "+=5000",
          // markers: true,
        },
      });
      // close the blueScreen
      gsap.fromTo(
        blueScreenRef.current,
        {
          scaleY: 1,
        },
        {
          scaleY: 0,
          scrollTrigger: sharedScrollTrigger,
        }
      );
      // other anims...
    }, sectionRef);
    return () => ctx.revert();
  }, []);

What am i doing wrong in here brothas? I think i suck with the svg's @PointC ? any help would be greatly appreciated.

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