我是Angular的新手,並且想在JQuery中實現相同的簡單函數擴展, 但使用指令(據我瞭解,這是它應該如何完成的)。AngularJS計數器達到目標數
確實準備好了嗎?
我的搜索結果只有JQuery解決方案,我不知道如何將其轉換爲Angular。
這就是我需要做的:
鏈接,例如:http://jsfiddle.net/YWn9t/
你能幫忙嗎?
函數聲明:
$.fn.countTo.defaults = {
from: 0, // the number the element should start at
to: 100, // the number the element should end at
speed: 1000, // how long it should take to count between the target numbers
refreshInterval: 100, // how often the element should be updated
decimals: 0, // the number of decimal places to show
onUpdate: null, // callback method for every time the element is updated,
onComplete: null, // callback method for when the element finishes updating
};
如何使用:
jQuery(function($) {
$('.timer').countTo({
from: 50,
to: 2500,
speed: 5000,
refreshInterval: 50,
onComplete: function(value) {
console.debug(this);
}
});
});
HTML:
<span class="timer"></span>
摘自:在本指令
哇,它看起來像一個很好的指令,但它看起來它只支持,倒計時,而不是COUNTUP –
默認情況下它是計數。 – Chandermani
有沒有辦法在達到某個值時停止這個定時器? –