Jump to content
Search Community

Toggle Class Updates the Wrong Component

NewbieScroll test
Moderator Tag

Go to solution Solved by GreenSock,

Recommended Posts

Hi there, 

I'm experimenting with Scroll Trigger. Below is the code snippet 

Goal : When the green component enters the third section, I want to add a class 'active' and updates the CSS of green component. 
However, the code below seems to add 'active' class to the section instead of my green component


 

// HTML below
<section> one </section>
<section> two </section>
<section id="three"> three </section>
<section> four </section>
<section> fiive </section>
<div id="green"> another component </div>

// CSS Below 
section{
  border:1px solid black;
  height:500px;
  margin: 25px auto;
}
#green{
  font-size:30px;
  background-color:green;
  height:50px;
  width:500px;
  position:fixed;
  top:0;
}
.active{
  color:white ;
  background-color:black;
}

// JS below
gsap.registerPlugin(ScrollTrigger)
gsap.to('#green',{
  scrollTrigger:{
    trigger: "#three",
    start:'top top',
    end:"9999",
    markers:true,
    toggleClass:"active"
  
  },
   
})

 

Thanks for your help!!! :))

 

See the Pen gOXPKNx by Newbie2019 (@Newbie2019) on CodePen

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