我是 Angular 的新手,想在 JQuery 中实现同样简单的函数扩展,
但使用指令(据我所知,这就是应该如何完成的)。
有人知道准备实施吗?
我的搜索最终只找到了 JQuery 解决方案,但我不知道如何将其转换为 Angular。
这就是我需要做的:
链接到示例:http://jsfiddle.net/YWn9t/ 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>
取自:堆栈溢出 https://stackoverflow.com/questions/2540277/jquery-counter-to-count-up-to-a-target-number