Search code examples
javascriptgsap

Using GSAP plugins


I'm new to GSAP, and I'm trying to build a function where it will scroll to a certain point on a page, but I don't quite understand how to correct use GSAP plugins. I've managed to use scripts to tween colour, size and position but I can't get scroll to work.

My goal is to have the page scroll down to a specific point (I've just set it to 9999 for the purpose of testing) when clicking the button that says "Iterate". Nothing happens.

My code looks like -

<head>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css">  
    <link type="text/css" rel="stylesheet" href="custom.css"/>
    <script src="http://cdnjs.cloudflare.com/ajax/libs/gsap/latest/TweenMax.min.js"></script>   
    <script src="https://cdnjs.cloudflare.com/ajax/libs/ScrollMagic/2.0.3/ScrollMagic.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/ScrollMagic/2.0.3/plugins/animation.gsap.min.js"></script>
    <script src="custom.js"></script>
</head>
<body>
    <div class="bigtop">
            <button class="iconDo" onclick="scrollFour()">
                <i class="fa fa-wrench fa-2x"></i>      
                <h2>Iterate</h2>
            </button>
    </div>
    <div class="tier1">
        <h1>One</h1>
        <p>Body Text</p>
    </div>
    <div class="tier2">
        <h1>Two</h1>
        <p></p>
    </div>
    <div class="tier3">
        <h1>Three</h1>
        <p></p> 
    </div>
    <div class="tier4">
        <h1>Test</h1>
        <p></p>
    </div>
    <div class="tier5">
        <h1>Four</h1>
        <p></p>
    </div>      
</body>

The script I'm using -

var scrollFour = function(){
    TweenLite.to(window, 2, {scrollTo:{y:9999}, ease:Power2.easeOut});
}

And the CSS, if it's relevant -

*{
    margin: 0;
    padding: 0;
}

body{
    width: 100%;
}   

div{
    width: 100%;
    padding: 0 0 30px 0;
    height: 300px;
}

h1{
    padding: 50px 0 0 200px;
    color: #FFFFFF;
    font-family: arial, sans-serif;
}

h2{
    font-family: arial, sans-serif;
    padding: 20px 0;
}

p{
    padding: 20px 0 0 200px;
    color: #FFFFFF;
    font-family: arial, sans-serif; 
    width: 800px;
}

.iconDo{
    border-radius: 10px;
    float: left;
    text-align: center;
    padding: 10px 20px;
    color: #FFFFFF;
}

.bigtop{    
    background-color: #6200EA;
    position: fixed;
    top: 0;
    width: 100%;
    height: 100px;  
    box-shadow: 0 0 30px 0 #000000;     
}

.tier1{
    background-color: #111111;
    margin: 100px 0 0 0;    
}

.tier2{
    background-color: #333333;
}

.tier3{
    background-color: #555555;
}

.tier4{
    background-color: #777777;
}

.tier5{
    background-color: #999999;
}

Solution

  • It looks like you just forgot to load the ScrollToPlugin:

    <script src="http://cdnjs.cloudflare.com/ajax/libs/gsap/1.18.0/plugins/ScrollToPlugin.min.js"></script>