Jump to content
Search Community

Help create an effect of text growing and the background on it becoming the background of the page

Eylon
Moderator Tag

Recommended Posts

Posted

Hello,
I'm trying to create a text effect whose background is a video, and when scrolling down the text grows until it becomes the new screen with the video,
I will share the code. I succeeded in the effect I want, which is simply that the text grows and you get the new background.

 

https://codesandbox.io/p/sandbox/new

Gaming.jsx Gaming.scss

GSAP Helper
Posted

Without a minimal demo, it's very difficult to troubleshoot; the issue could be caused by CSS, markup, a third party library, a 3rd party script, etc. Would you please provide a very simple CodePen or Stackblitz that illustrates the issue? 

 

Please don't include your whole project. Just some colored <div> elements and the GSAP code is best. See if you can recreate the issue with as few dependencies as possible. Start minimal and then incrementally add code bit by bit until it breaks. Usually people solve their own issues during this process! If not, at least we have a reduced test case which greatly increases your chances of getting a relevant answer.

 

See the Pen aYYOdN by GreenSock (@GreenSock) on CodePen.

that loads all the plugins. Just click "fork" at the bottom right and make your minimal demo

 

Using a framework/library like React, Vue, Next, etc.? 

CodePen isn't always ideal for these tools, so here are some Stackblitz starter templates that you can fork and import the gsap-trial NPM package for using any of the bonus plugins: 

 

Please share the StackBlitz link directly to the file in question (where you've put the GSAP code) so we don't need to hunt through all the files. 

 

Once we see an isolated demo, we'll do our best to jump in and help with your GSAP-specific questions. 

GSAP Helper
Posted

Hi there! I see you're using React -

Proper cleanup is very important with frameworks, but especially with React. React 18 runs in strict mode locally by default which causes your useEffect() and useLayoutEffect() to get called TWICE.

 

Since GSAP 3.12, we have the useGSAP() hook (the NPM package is here) that simplifies creating and cleaning up animations in React (including Next, Remix, etc). It's a drop-in replacement for useEffect()/useLayoutEffect(). All the GSAP-related objects (animations, ScrollTriggers, etc.) created while the function executes get collected and then reverted when the hook gets torn down.

 

Here is how it works:

const container = useRef(); // the root level element of your component (for scoping selector text which is optional)

useGSAP(() => {
  // gsap code here...
}, { dependencies: [endX], scope: container }); // config object offers maximum flexibility

Or if you prefer, you can use the same method signature as useEffect():

useGSAP(() => {
  // gsap code here...
}, [endX]); // simple dependency Array setup like useEffect()

This pattern follows React's best practices.

 

We strongly recommend reading the React guide we've put together at https://gsap.com/resources/React/

 

If you still need help, here's a React starter template that you can fork to create a minimal demo illustrating whatever issue you're running into. Post a link to your fork back here and we'd be happy to take a peek and answer any GSAP-related questions you have. Just use simple colored <div> elements in your demo; no need to recreate your whole project with client artwork, etc. The simpler the better. 

Posted

thanks u for answers,

 

I changed the code to use with useGsp

Currently the animation grows with scrolling down, but I want the animation to grow so that the video behind is the next background. Which will be 100vh screen size

 

https://codesandbox.io/p/devbox/7969wq?migrateFrom=hrzhd5

 

Also how do I change the background from white to var i try but than the effect cancel?

 

Thank u.

Posted

Hi,

 

Sorry but your demo is not working:

Qn6tzic.png

 

Please try to create a minimal demo in Stackblitz or make sure that the link you post works as expected.

Posted
 
Maybe the link will work and just in case I write the code here
 
 
 
import React, { useEffect, useRef } from "react";
import { gsap } from "gsap";
import { ScrollTrigger } from "gsap/ScrollTrigger";
import "./Gaming.scss"; // ייבוא קובץ ה-SASS
import video from "../../../assets/videos/hero-1.mp4";
 
gsap.registerPlugin(ScrollTrigger); // רישום ScrollTrigger ב-GSAP
 
const Gaming = () => {
  const svgRef = useRef(null); // הפניה ל-SVG
 
  useEffect(() => {
    gsap.to(svgRef.current, {
      scale: 10, // מגדיל את ה-SVG עד פי 10
      ease: "power1.out", // אנימציה חלקה
      scrollTrigger: {
        trigger: svgRef.current, // מפעיל את האנימציה כשה-SVG נכנס למסך
        start: "top bottom", // מתחיל את האנימציה כשמגיעים לאמצע המסך
        end: "bottom top", // מסיים כשהגלילה מסתיימת
        scrub: 2, // הופך את האנימציה לחלקה לפי הגלילה
      }
    });
  }, []);
 
  return (
    <div className="gaming-container">
      {/* ווידאו כרקע */}
      <div className="video-background">
        <video autoPlay playsInline muted loop preload="auto">
          <source src={video} type="video/mp4" />
        </video>
      </div>
 
     
 
      {/* טקסט עם אפקט SVG */}
      <svg
        ref={svgRef} // חיבור ל-GSAP
        className="gaming-svg"
        width="100%"
        height="100%"
        viewBox="0 0 800 400"
      >
        <defs>
          <mask id="text-mask">
            <rect width="100%" height="100%" fill="white" />
            <text
              x="50%"
              y="50%"
              dominantBaseline="middle"
              textAnchor="middle"
              fill="black"
              fontSize="100"
              fontWeight="bold"
            >
              I LOVE SVG!
            </text>
          </mask>
        </defs>
        <rect width="100%" height="100%" fill="white" mask="url(#text-mask)" />
      </svg>
    </div>
  );
};
 
export default Gaming;
 
 
 
 
 
 
.gaming-wrapper {
    position: relative;
    height: 200vh; // יצירת גלילה ארוכה
    overflow: hidden;
}
 
/* ווידאו כרקע */
.video-background {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
}
 
.video-background video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
 
/* הרקע החדש שמופיע אחרי הגלילה */
.background-new {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, #1a1a1a, #333333); // צבע רקע חדש
    opacity: 0; // ברירת מחדל - מוסתר
    transition: opacity 1.5s ease-in-out;
    z-index: -1; // נמוך יותר מהטקסט כדי לא להפריע
}
 
.gaming-container {
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    overflow: hidden;
}
 
/* ווידאו כרקע */
.video-background {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -1; // מבטיח שהוידאו יהיה ברקע
}
 
.video-background video {
    width: 100%;
    height: 100%;
    object-fit: cover; // מבטיח שהוידאו ימלא את כל המסך
}
 
/* טקסט עם אפקט */
.gaming-svg {
    position: relative;
    width: 100%;
    height: 100%;
}





 
Posted

Hi,

 

There were several issues in your demo, first you were importing a video file that is not there, so that throws an error. You weren't using our useGSAP hook neither, is better to rely on our hook rather than useEffect, in order to not have to worry about cleanup and simplify other things such scoping.

 

Here is a fork of your demo

https://stackblitz.com/edit/react-boxhdx5x?file=src%2FApp.jsx

 

Also you can have a look at this thread as well:

 

Finally maybe you could use MorphSVG in order to morph the text  or a single letter from a Path into using the entire SVG canvas:

https://gsap.com/docs/v3/Plugins/MorphSVGPlugin

 

Hopefully this helps

Happy Tweening!

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