12
A
回答
11
你所需要的是在步驟參數功能。
var a = 1;
jQuery('#dummy').animate({ /* animate dummy value */},{
duration: 5000,
step: function(now,fx){
a = 1 + ((now/100)*9);
}
});
0
使用的setInterval:
percentage = 0;
startValue = 1;
finishValue = 5;
currentValue = 1;
interval = setInterval(function(){
percentage ++;
currentValue = startValue + ((finishValue - startValue) * percentage)/100;
doSomething(currentValue);
if (percentage == 100) clearInterval(interval);
}, duration/100)
function doSomething(val) { /*process value*/}
1
var blub = 1;
setTimeout(function() {
blub = 10;
}, 5000);
+0
Ahahahhahahahhahahahha,這太有趣了! +1 – super
0
增量與setTimeout
x = 1
for(i=0;i<1000;i+=100){
setTimeout(function(){
console.log(x++)
},i)
}
2
0
的Html標記爲
的Html
<span id="changeNumber">1</span>
您可以在5秒後改變其值。
JQuery的:
setInterval(function() {
$('#changeNumber').text('10');
},5000);
23
嘗試:
$({someValue: 0}).animate({someValue: 10}, {
duration: 5000,
step: function() {
$('#el').text(Math.ceil(this.someValue));
}
});
<div id="el"></div>
9
0
除了關係答案 - 你沒有事件需要追加虛擬元素到DOM。我這樣做:
$.fn.animateValueTo = function (value) {
var that = this;
$('<span>')
.css('display', 'none')
.css('letter-spacing', parseInt(that.text()))
.animate({ letterSpacing: value }, {
duration: 1000,
step: function (i) {
that.text(parseInt(i));
}
});
return this;
};
相關問題
- 1. 將變量傳遞給.animate()函數JQuery
- 2. 變量不工作scrollTop值內.animate()
- 3. Animate偏移量()。左側帶哈希值變化jQuery
- 4. jQuery animate()改變文本
- 5. JQuery Animate
- 6. Jquery:變量賦值
- 7. 停止Jquery .Animate()新的.Animate()
- 8. 如何在jQuery的animate()函數中使用變量?
- 9. 無法從jQuery變量中分配'頂部'Animate
- 10. jQuery animate()爲什麼不能使用變量css屬性?
- 11. 將jQuery變量賦值給php變量
- 12. 衝突之間-webkit變換和jQuery .animate()
- 13. Animate自定義對象變量
- 14. jquery animate height bouncing
- 15. jQuery animate set fallback
- 16. Waypoint Jquery Animate
- 17. jQuery的.animate()
- 18. Animate content div'height'to'Auto'onclick - jQuery
- 19. 與jQuery Animate translate3d
- 20. jQuery .animate()問題
- 21. JQuery替代.animate?
- 22. jQuery .animate問題
- 23. JQuery Animate Z-Index?
- 24. JavaScript jQuery Animate
- 25. jQuery animate .prepend
- 26. ToggleClass animate jQuery?
- 27. jquery animate()問題
- 28. jQuery javascript-scrollTop animate
- 29. jQuery Animate問題
- 30. Jquery-Relatively animate DIV
是否要在固定時間後繼續增加此變量? – Sibu
應該「平穩」增加。我忘了說... – Marv
你有一個優雅的解決方案在這裏http://stackoverflow.com/a/9324325/607874 –