gpt4 book ai didi

jquery - TweenMax 在 ScrollMagic 之前设置动画

转载 作者:行者123 更新时间:2023-11-28 16:11:37 24 4
gpt4 key购买 nike

TweenMax 在 ScrollMagic 之前运行

我正在尝试使用 TweenMaxScrollMagic 使页眉在滚动页面时缩小,但动画在不等待滚动的情况下触发。

这是我的代码:

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

我还有以下顺序的脚本 -

  1. J查询
  2. 吐温最大
  3. 滚动魔术

最佳答案

脚本被触发是因为 header 元素已经在触发位置(=视口(viewport)的顶部)。将 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 - TweenMax 在 ScrollMagic 之前设置动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38254666/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com