Jump to content
Search Community

gsap.registerPlugin(ScrollTrigger) doesn't work

dieKachba test
Moderator Tag

Recommended Posts

Hello,

 

so I am using the Program for 4 days now and i can't solve the Problem.

I have a black Screen and my goal is it to see an image from a car and when you scroll its zooming in and fade away and behind that section is a new image with some text.

 

But somehow I only receive a blackscreen.

 

html

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Autohaus Kaya</title>
        <link rel="stylesheet" href="zzzzzzzzzzzzzzzzzzzzzzzzzTest.css">
        <link rel="preconnect" href="https://fonts.googleapis.com">
        <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
        <link href="https://fonts.googleapis.com/css2?family=Dancing+Script:wght@700&display=swap" rel="stylesheet">
        <link href="https://fonts.googleapis.com/css2?family=Dancing+Script:wght@700&family=Oooh+Baby&display=swap" rel="stylesheet">
        <link href="https://fonts.googleapis.com/css2?family=Satisfy&display=swap" rel="stylesheet">
        <link href="https://fonts.googleapis.com/css2?family=Qwitcher+Grypen:wght@700&display=swap" rel="stylesheet">
        <link href="https://pro.fontawsome.com/releases/v5.10.0/css/all.css" rel="stylesheet">
        <link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
        <link href="https://fonts.googleapis.com/css2?family=Dancing+Script&display=swap" rel="stylesheet">
        <link rel="stylesheet" href="https://unpkg.com/aos@next/dist/aos.css" />

        <link rel="stylesheet" type="text/css" href="style.css">
        <link href="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.11.1/gsap.min.js">
        
        <!-- CSS only -->
        
        <link rel="stylesheet" type="text/css" href="//cdn.jsdelivr.net/gh/kenwheeler/slick@1.8.0/slick/slick-theme.css"/>
        <link rel="stylesheet" type="text/css" href="//cdn.jsdelivr.net/gh/kenwheeler/slick@1.8.0/slick/slick.css"/>
        <link rel="stylesheet" type="text/css" href="slick.css">
        <link rel="stylesheet" type="text/css" href="slick-theme.css"/>


        <style>
            html{
                scroll-behavior: smooth;
                scrollbar-width: normal;
            }
        </style>
    </head>

    <body>
        <section><div class="zoom-element">Panel 1</div></section>

        <section><div class="zoom-element">Panel 2</div></section>

        <section><div class="zoom-element">Panel 3</div></section>














        <script src="https://unpkg.com/aos@next/dist/aos.js"></script>
        <script>
        AOS.init({
            duration: 800,
            once: true,
        });
        </script>
        <script src="zzzzzzzzzzzzzzzzzzzzzzzzzTest.js"></script>
        
        <script src="gaso/gsap-public/esm/ScrollToPlugin.js"></script>
        <script src="gaso/gsap-public/esm/ScrollTrigger.js"></script>
        <script src="gaso/gsap-public/minified/ScrollTrigger.min.js"></script>
        <script src="gaso/gsap-public/minified/ScrollToPlugin.min.js.map"></script>
        <script src="gaso/gsap-public/minified/ScrollTrigger.min.js"></script>
        <script src="gaso/gsap-public/minified/ScrollTrigger.min.js.map"></script>
        <script src="gaso/gsap-public/src/ScrollToPlugin.js"></script>
        <script src="gaso/gsap-public/src/ScrollTrigger.js"></script>
        <script src="gaso/gsap-public/umd/ScrollToPlugin.js"></script>
        <script src="gaso/gsap-public/umd/ScrollTrigger.js"></script>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.11.1/gsap.min.js"></script>
        <script src="gaso/gsap-public/minified/gsap.min.js"></script>

        <script src="gaso/gsap-public/esm/ScrollToPlugin.js"></script>
        <script src="jquery-3.6.1.min.js"></script>
        <script src="https://code.jquery.com/jquery-3.6.1.js"></script>
        <script src="jquery.cycle2.min.js"></script>
        


        

        

        </body>
</html>

 

css

*{
    box-sizing: border-box;
    margin: 0;
    padding: 0;
  }
  
  body{
    background: black;
    color: white;
  }
  
  section{
    height: 100vh;
    width: 100%;
    padding: 10vw;
    display: flex;
    align-items: center;
    justify-content:center;
  }
  
  .zoom-element{
    width: calc(100% - 10vw);
    height: calc(100% - 10vw);
    display: flex;
    font-size: 100px;
    position: fixed;
    top: 5vw;
    left: 5vw;
    align-items: center;
    justify-content:center;
    transform: scale(0.1);
    opacity:0;
    border: 5px solid white;
  }

js

gsap.registerPlugin(ScrollTrigger);

// BLUR PLUGIN

(function() {
	const blurProperty = gsap.utils.checkPrefix("filter"),
		    blurExp = /blur\((.+)?px\)/,
		    getBlurMatch = target => (gsap.getProperty(target, blurProperty) || "").match(blurExp) || [];

	gsap.registerPlugin({
		name: "blur",
		get(target) {
			return +(getBlurMatch(target)[1]) || 0;
		},
		init(target, endValue) {
			let data = this,
          filter = gsap.getProperty(target, blurProperty),
          endBlur = "blur(" + endValue + "px)",
          match = getBlurMatch(target)[0],
          index;
      if (filter === "none") {
        filter = "";
      }
      if (match) {
        index = filter.indexOf(match);
        endValue = filter.substr(0, index) + endBlur + filter.substr(index + match.length);
      } else {
        endValue = filter + endBlur;
        filter += filter ? " blur(0px)" : "blur(0px)";
      }
      data.target = target; 
      data.interp = gsap.utils.interpolate(filter, endValue); 
		},
		render(progress, data) {
			data.target.style[blurProperty] = data.interp(progress);
		}
	});
})();


// SCROLL TIMELINE SET UP

console.clear();

select = (e) => document.querySelector(e);
selectAll = (e) => document.querySelectorAll(e);

const zoomTrigger = selectAll("section");

// ZOOM IN

zoomTrigger.forEach((zoomTrigger, i) => {
  let zoomAnimation = gsap.timeline({
    scrollTrigger: { 
      id: "zoom-element",
      trigger: zoomTrigger,
      scrub:1,
      start: "top bottom",
      end: "center center",
      pin:false,
      //markers: {startColor: "orange", endColor: "blue"},
      toggleActions: "play reset play reset",
    },
  });

  zoomAnimation
    
.to(zoomTrigger.querySelectorAll(".zoom-element"),
    {
      scale: 1, 
    opacity: 1,
    },
  );
});

// FADE OUT

zoomTrigger.forEach((zoomTrigger, i) => {
  let fadeAnimation = gsap.timeline({
    scrollTrigger: { 
      id: "fade",
      trigger: zoomTrigger,
      scrub:1,
      start: "center center",
      end: "center 0%",
      pin:false,
      markers: false,
      toggleActions: "play reset play reset",
    },
  });

  fadeAnimation
    
.to(zoomTrigger.querySelectorAll(".zoom-element"),
    {
      opacity: 0, 
      scale:15,
      //blur:3,
    },
  );
});

 

 

Thank you all for your help :)

Link to comment
Share on other sites

  • dieKachba changed the title to gsap.registerPlugin(ScrollTrigger) doesn't work

It's pretty tough to troubleshoot without a minimal demo - the issue could be caused by CSS, markup, a third party library, your browser, an external script that's totally unrelated to GSAP, etc. Would you please provide a very simple CodePen or CodeSandbox that demonstrates the issue? 

 

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

 

Here's a starter CodePen that loads all the plugins. Just click "fork" at the bottom right and make your minimal demo

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

 

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

Link to comment
Share on other sites

Sorry I don't know how to put the Codepen inside the textbox. I hope the direct link to the Pens that i did on my account still help out, to figure out where the problem is. 

 

If I put the excact same code in Visual Studio Code my hompage remains black. 

See the Pen wvjgzab by david-buble (@david-buble) on CodePen

 

But I got the GSAP ScrollTrigger.js file and the GSAP.js file in my Code(in Visual Studio Code).  But it's still a blackscreen.

<!DOCTYPE>
<html>
  <head>
    ....
  </head>
  <body>
    ....
    ....
	<script src="https://unpkg.com/gsap@3/dist/ScrollTrigger.min.js"></script>
	<script src="https://unpkg.co/gsap@3/dist/gsap.min.js"></script>
  </body>
</html>

 

So I copy pasted my Code in Codepen and I added two importent js files:

1.GSAP 3.x 

Quote

 

2. GSAP ScrollTrigger 3.x 

Quote

 

This is the link to the working code.

See the Pen BaxpLoE by david-buble (@david-buble) on CodePen

 

So on CodePen it's working but on my homepage it's still the blackscreen.

 

 

 

EDIT:

 

I solved the Problem. I was putting the script file in the body of the code but that was stupid.

Quote
<script  src="https://unpkg.com/gsap@3/dist/ScrollTrigger.min.js"></script>

 

So i putted the js file in the head of my code and wrote type="text/javascript" into the script and it worked.

Quote
<script type="text/javascript" src="https://unpkg.com/gsap@3/dist/ScrollTrigger.min.js"></script>

 

 

  • Like 1
Link to comment
Share on other sites

Hi @dieKachba and welcome to the GreenSock forums!

 

Glad to see that you were able to solve the issue!

 

Regardless of where you put your script tags with the GSAP files, they can go before the closing body tag, you only have to put your custom code after the GSAP files, not before.

 

Not Working

<script src="zzzzzzzzzzzzzzzzzzzzzzzzzTest.js"></script>

<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.11.1/gsap.min.js"></script>
<script src="gaso/gsap-public/minified/ScrollTrigger.min.js"></script>
<script src="gaso/gsap-public/minified/ScrollTrigger.min.js.map"></script>

Should work

<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.11.1/gsap.min.js"></script>
<script src="gaso/gsap-public/minified/ScrollTrigger.min.js"></script>
<script src="gaso/gsap-public/minified/ScrollTrigger.min.js.map"></script>

<!-- After adding GSAP core and plugins add your code -->
<script src="zzzzzzzzzzzzzzzzzzzzzzzzzTest.js"></script>

Finally in the first post you added a bunch of duplicate files and some files for UMD modules as well. My advice is that for simple setups is better to just use the regular files from the downloaded zip and the minified files in production or use the CDN files directly. Take a look at the installation helper section in the docs for a better grasp on how you can use GSAP in your projects:

 

https://greensock.com/docs/v3/Installation#installer

 

Happy Tweening!!!

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