Aditya Shukla
Aditya Shukla

Reputation: 1

Gsap Scroll Trigger Issue

I am creating a portfolio website for me. The issue is related with GSAP ScrollTrigger not working.

I am trying to create a scroll trigger animation that when i move to my next section it should turn it background to black from white but gsap scrolltrigger not working properly. I can't get the error resolved

HTML

<div class="page2 page"></div>

CSS

.page2 {
  background-color: #efeae3;
  height: 100vh;
  width: 100vw;
  align-items: center;
  display: flex;
  justify-content: center;
}

JS

gsap.registerPlugin(ScrollTrigger);

function squareMove() {
  let tk = gsap.timeline({
    scrollTrigger: {
      trigger: ".page2",
      scrub: true,
    },
  });

  tk.to(".page2", {
    backgroundColor:"#b1b1b1",
    duration: 1, 
  });
}
squareMove();

Upvotes: 0

Views: 104

Answers (1)

Mohammadamin Alizadeh
Mohammadamin Alizadeh

Reputation: 314

It's working here

gsap.registerPlugin(ScrollTrigger);

function squareMove() {
  let tk = gsap.timeline({
    scrollTrigger: {
      trigger: ".page2",
      scrub: true,
    },
  });

  tk.to(".page2", {
    backgroundColor:"#b1b1b1",
    duration: 1, 
  });
}
squareMove();
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <style>
    .page2 {
      background-color: #efeae3;
      height: 200vh;
      width: 50vw;
      align-items: center;
      display: flex;
      justify-content: center;
    }
  </style>
  
  <title>Document</title>
</head>
<body>
  <div class="page2 page"></div>

  <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/gsap.min.js"></script>
  <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/ScrollTrigger.min.js"></script>
</body>
</html>

Upvotes: 0

Related Questions