jquery中动画(animal)只运行一次的问题!
本人想要编写的功能是:组件向左滑动一段距离之后,滑动结束之后,将组件复原(回到原来位置)!
具体代码:
$("#content").animate({right:'0'},3000,function() {
var first=$("#content li:first-child").clone(true);
$("#content li:first-child").remove();
$("#content").append(first);
$("#content").animate({left:'0'},1);
});
出现的问题是$("#content").animate({left:'0'},1);
在复原之后,第二次执行动画效果的时候不执行了!也就是第二次的动画效果失效了!这个问题我没有找到原因!
解决方案:
$("#content").animate({right:'+=200px'},3000,function() {
var first=$("#content li:first-child").clone(true);
$("#content li:first-child").remove();
$("#content").append(first);
$("#content").animate({right:'-=200px'},1);
});
不要设置right固定的值,通过设定right:'+=200px'
和right:'-=200px'
相对值来实现此功能!!!!