TweenMax在ScrollMagic之前运行
我试图在使用TweenMax
和ScrollMagic
滚动浏览页面时使标题缩小,但是动画正在触发而无需等待Scroll。
这是我的代码:
$(document).ready(function(){
var header = $('header')
//init the controller
var controller = new ScrollMagic.Controller();
var tween = TweenMax.to(header ,1 ,{height: 100});
var scene = new ScrollMagic.Scene({
triggerElement: header
})
.setTween(tween)
.addTo(controller);
});
body {
margin: 0;
padding: 0;
background-color: #e95849;
font-family: sans-serif;
}
ul {
margin: 0;
padding: 0;
list-style-type: none;
}
ul:after {
content: "";
display: table;
clear: both;
}
li {
float: right;
color: #000;
padding: 20px 10px;
}
header {
background-color: #fff;
height: 150px;
position: fixed;
width: 100vw;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/1.18.5/TweenMax.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/ScrollMagic/2.0.5/ScrollMagic.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/ScrollMagic/2.0.5/plugins/animation.gsap.min.js"></script>
<header>
<nav>
<ul id="animate">
<li>ABOUT</li>
<li>WORK</li>
<li>DESIGN</li>
<li>CONTACT</li>
</ul>
</nav>
</header>
<div style="height: 2000px"></div>
我还有以下顺序的脚本-
jQuery的
吐温麦克斯
ScrollMagic
最佳答案
因为header
元素已经在触发位置(=视口的顶部),所以脚本被触发。将offset: 1
添加到场景-这将使其等待直到向下滚动至少一个像素。 (将该值更改为您喜欢的任何值)
$(document).ready(function(){
var header = $('header')
//init the controller
var controller = new ScrollMagic.Controller();
var tween = TweenMax.to(header ,1 ,{height: 100});
var scene = new ScrollMagic.Scene({
triggerElement: header,
offset: 1
})
.setTween(tween)
.addTo(controller);
});
body {
margin: 0;
padding: 0;
background-color: #e95849;
font-family: sans-serif;
}
ul {
margin: 0;
padding: 0;
list-style-type: none;
}
ul:after {
content: "";
display: table;
clear: both;
}
li {
float: right;
color: #000;
padding: 20px 10px;
}
header {
background-color: #fff;
height: 150px;
position: fixed;
width: 100vw;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/1.18.5/TweenMax.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/ScrollMagic/2.0.5/ScrollMagic.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/ScrollMagic/2.0.5/plugins/animation.gsap.min.js"></script>
<header>
<nav>
<ul id="animate">
<li>ABOUT</li>
<li>WORK</li>
<li>DESIGN</li>
<li>CONTACT</li>
</ul>
</nav>
</header>
<div style="height: 2000px"></div>
关于jquery - ScrollMagic之前的TweenMax动画,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/38254666/