简体   繁体   English

交换类不会清除先前的补间值

[英]Interchanging classes doesn't clear previous tween values

I am working on some sort of animation so I have prepared a demo which relates exactly to the task. 我正在制作某种动画,所以我准备了一个与任务完全相关的演示。 I am inter-changing the classes after the first timeline completes and running another timeline when the user clicks the second time. 我在第一个时间轴完成后交换类,并在用户第二次单击时运行另一个时间轴。 The problem is when the second timeline is played, the tween adds the previous tween values to the element which I am tweening on the second click. 问题是当播放第二个时间轴时,补间将先前的补间值添加到第二次单击时要补间的元素上。 If you look at the below example, when running second timeline ie home_slide_2, the block_1 element is taking x value from the previous tween making animte both x and y values. 如果看下面的示例,则在运行第二个时间轴(即home_slide_2)时,block_1元素将从上一个补间中获取x值,从而同时对x和y值进行动画处理。 Can anyone guide me on this that what I am doing wrong here. 谁能在这方面指导我我在做什么错。

 $('.arrow').on("click",function() { var id = $(this).data('id'); if(id == "slide_1"){ // transition of first slide var home_slide_1 = new TimelineMax({paused:(true),onComplete:reset}) .to(".block_1", 1.5, {y: 30,ease:Power4.easeOut},"s") .to(".block_2", 1.5, {x: 30,ease:Power4.easeOut},"s"); function reset(){ $(".block_1").addClass('block_2').removeClass('block_1').removeAttr("style"); $(".av2").addClass('block_1').removeClass('block_2').removeAttr("style"); }; home_slide_1.play(); $(this).data('id', "slide_2"); } else if(id == "slide_2"){ // transition of second slide var home_slide_2 = new TimelineMax({paused:(true)}) .to(".block_1", 1.5, {y: 30,ease:Power4.easeOut}); home_slide_2.play(); } }); 
 .arrow{ float:right; width:50px; height:50px; background:red; curspor:pointer } .ar1{ float:right; width:50px; height:50px; background:black; curspor:pointer } .block_1{ background:green; float:left; width:100px; height:100px; } .block_2{ background:blue; float:left; width:100px; height:100px; } 
 <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.20.3/TweenMax.min.js"></script> <div class="arrow" data-id="slide_1"></div> <div class="block_1 av1"></div> <div class="block_2 av2"></div> 

You can use clearProps to clear the tween values 您可以使用clearProps清除补间值

else if(id == "slide_2"){

   //clearing the tween values in block_1
   TweenMax.set(".block_1", {clearProps:"all"}); 

   // transition of second slide
   var home_slide_2 = new TimelineMax({paused:(true)})
   .to(".block_1", 1.5, {y: 30,ease:Power4.easeOut});

   home_slide_2.play();      
 }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM