【发布时间】:2015-04-21 06:53:58
【问题描述】:
我需要创建运动和颜色变化的平滑过渡。现在,文本首先被动画化,只有在动画结束后才会发生颜色变化过渡。如何在移动期间更改文本的颜色?
这是 HTML 代码:
<button type="button" class="btn btn-danger center-block" id="btn">start animation</button>
<div id="meterText" class="col-centered"></div> <!-- animated text -->
CSS:
#meterText{
display:none;
width: 50px;
height: 10px;
margin-left: 40px;
position: absolute;
top: 211px;
font-size: 15px;
color: red;
}
jQuery:
var counter=0;
$("#btn").on('click',function(event){
counter++;
console.log(event.target.id + " was clicked");
switch(counter){
case 1:{
$("#meterText").text("first transition");
$("#meterText").hide().fadeIn();
break;
}
case 2:{
$("#meterText").animate({'marginTop':"-=83px"});
$("#meterText").text("second transition");
$("#meterText").animate({color: "#FFD700"});
break;
}
case 3:{
$("#meterText").text("third transition");
$("#meterText").animate({'marginTop':"-=68px"});
$("#meterText").animate({color: "#44c767"});
break;
}
}
});
【问题讨论】:
-
在第一个动画函数中也传递颜色变化
-
查看Fiddle
-
或者你可以传递 queue: false 作为参数,如果你想保持动画分开。 jsfiddle.net/K9LpL/1048
标签: javascript jquery css jquery-animate coloranimation