【发布时间】:2013-01-17 18:37:50
【问题描述】:
我能够制作一个宽度为 150 像素的条形动画。现在我试着让它回到原来的位置,但只有当它到达终点时。为什么条件: if ($('#indicator').width() > '149px') 不起作用?如何做好?
$(function(){
$("#play").click(function() {
$("#indicator").animate({"width": "150px"}, 8400);
});
// indicador back to 0
if ($('#indicator').width() > '149px') {
$("#indicator").animate({"width": "1px"}, 100);
}
});
在这里查看和玩:http://jsfiddle.net/SwkaR/
【问题讨论】:
-
你的第二个函数在你的 DOM 准备好后立即运行,所以当你的动画完成时它不会触发!
-
console.log( $('#indicator').width() );应该告诉你原因。
标签: jquery conditional