【问题标题】:Using GSAP plugins使用 GSAP 插件
【发布时间】:2015-11-09 16:40:14
【问题描述】:

我是 GSAP 新手,我正在尝试构建一个可以滚动到页面上某个点的函数,但我不太明白如何正确使用 GSAP 插件。我已经设法使用脚本来补间颜色、大小和位置,但我无法滚动工作。

我的目标是在单击“迭代”按钮时让页面向下滚动到特定点(我刚刚将其设置为 9999 以进行测试)。没发生什么事。

我的代码看起来像 -

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

我正在使用的脚本 -

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

还有 CSS,如果相关的话 -

*{
    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;
}

【问题讨论】:

    标签: javascript gsap


    【解决方案1】:

    您好像忘记加载 ScrollToPlugin:

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

    【讨论】:

      猜你喜欢
      • 2018-12-19
      • 1970-01-01
      • 1970-01-01
      • 2022-10-02
      • 1970-01-01
      • 1970-01-01
      • 2015-08-29
      • 2021-08-26
      • 2018-06-10
      相关资源
      最近更新 更多