【发布时间】:2012-03-31 04:05:06
【问题描述】:
我正在使用 javascript 为一些符合 div 的文本设置动画。
textValue 可以是 14-92 之间的任何数字。然后我需要将此数字更改为百分比(介于 1 和 100 之间),并从 0 动画到百分比。问题是它显示 NaN,我不确定是什么原因造成的。
我相信问题就在whileValue = ...
上我已经在我的代码中声明了变量。
知道是什么导致了这个问题吗?
谢谢
$("#percent")
.delay(3000)
.animate({
bottom: textValue
}, {
step: function () {
whileValue = (Math.ceil(parseInt($(".progressbar-cover").css("bottom")-14)/78)*100);
$("#percent").html(whileValue); //Increase the number to whileValue inline with animating upwards
}
});
编辑:为@mike 添加了我的 html
<div class="progressbar">
<div style="position:absolute; left:-14px; bottom:0%;" id="percent">0%</div>
<span class="progressbar-value"><em class="progressbar-cover"></em></span>
</div>
【问题讨论】:
-
.css("bottom")未返回数字字符串。使用调试器并查看它返回的字符串。 -
$(".progressbar-cover").css("bottom")的值是多少? -
parseInt($(".progressbar-cover").css("bottom")必须返回一个字符串,试试(Math.ceil((parseInt($(".progressbar-cover").css("bottom"))-14)/78)*100)。
标签: javascript jquery syntax nan