【问题标题】:Reversal of Timeline causes part of Timeline to go "missing" on next play时间线的反转导致部分时间线在下一场比赛中“丢失”
【发布时间】:2016-08-13 21:11:07
【问题描述】:

以下代码创建了一个GSAP TimelineMax,它在第一次播放时完美运行。但是,在时间轴反转并且您再次播放后,TimelineMax 的后半部分“丢失”了。

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,如果您愿意使用的话。

如果能在修复时间线以使其正常运行方面提供任何帮助,我将不胜感激。

注意:你需要将鼠标悬停在盒子上才能看到动画

【问题讨论】:

    标签: javascript jquery html css gsap


    【解决方案1】:

    您应该使用fromTo 函数。否则scale 的值将不会恢复为1

    查看here

    我改变了这一行

    .from($(this).children("span.long"), 0.5, {scale: 0});
    

    .fromTo($(this).children("span.long"), 0.5, {scale: 0}, {scale: 1});
    

    【讨论】:

      猜你喜欢
      • 2020-08-19
      • 1970-01-01
      • 2017-05-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多