时间线的反转导致部分时间线在下一次播放时进入 "missing"
Reversal of Timeline causes part of Timeline to go "missing" on next play
以下代码创建了一个 GSAP TimelineMax,它在第一次播放时完美运行。但是,在时间线反转并且您再次播放后,TimelineMax
的后半部分变为 "missing"。
var tl = new TimelineMax();
$(".box").hover(function(){
tl = new TimelineMax();
tl.to($(this).children("span.short"), 0.5, {scale: 0})
.set($(this).children("span.short"), {css:{display: "none"}})
.set($(this).children("span.long"), {css:{display: "block"}})
.from($(this).children("span.long"), 0.5, {scale: 0});
},function() {
tl.reverse();
});
.box {
width: 200px;
height:100px;
text-align:center;
background: black
}
span {
color: white
}
.short {
display: block
}
.long {
display: none
}
<script src="https://code.jquery.com/jquery-3.1.0.min.js" integrity="sha256-cCueBR6CsyA4/9szpPfrX3s49M9vUU5BgtiJj06wt/s=" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/1.19.0/TweenMax.min.js"></script>
<div class="box">
<span class="short">S</span>
<span class="long">Long</span>
</div>
这里有一个 JSFiddle 如果您想使用一个。
如能帮助我修复时间表以使其正常工作,我将不胜感激。
注意:您需要将鼠标悬停在框上才能看到动画
您应该使用 fromTo
函数。否则 scale
的值将不会恢复为 1
.
看看here。
我改变了这一行
.from($(this).children("span.long"), 0.5, {scale: 0});
到
.fromTo($(this).children("span.long"), 0.5, {scale: 0}, {scale: 1});
以下代码创建了一个 GSAP TimelineMax,它在第一次播放时完美运行。但是,在时间线反转并且您再次播放后,TimelineMax
的后半部分变为 "missing"。
var tl = new TimelineMax();
$(".box").hover(function(){
tl = new TimelineMax();
tl.to($(this).children("span.short"), 0.5, {scale: 0})
.set($(this).children("span.short"), {css:{display: "none"}})
.set($(this).children("span.long"), {css:{display: "block"}})
.from($(this).children("span.long"), 0.5, {scale: 0});
},function() {
tl.reverse();
});
.box {
width: 200px;
height:100px;
text-align:center;
background: black
}
span {
color: white
}
.short {
display: block
}
.long {
display: none
}
<script src="https://code.jquery.com/jquery-3.1.0.min.js" integrity="sha256-cCueBR6CsyA4/9szpPfrX3s49M9vUU5BgtiJj06wt/s=" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/1.19.0/TweenMax.min.js"></script>
<div class="box">
<span class="short">S</span>
<span class="long">Long</span>
</div>
这里有一个 JSFiddle 如果您想使用一个。
如能帮助我修复时间表以使其正常工作,我将不胜感激。
注意:您需要将鼠标悬停在框上才能看到动画
您应该使用 fromTo
函数。否则 scale
的值将不会恢复为 1
.
看看here。
我改变了这一行
.from($(this).children("span.long"), 0.5, {scale: 0});
到
.fromTo($(this).children("span.long"), 0.5, {scale: 0}, {scale: 1});