我发现了一个不错的jQuery增量脚本。增量部分可以接受函数或只是一个常规数字。我期待在1和100之间的随机数增加。我将如何为此编写函数?如何为这个jquery增量插件编写一个函数?
$(document).ready(function()
{
$('.tick').ticker(
{
incremental : 1,
delay : 1500,
separators : true
});
$(".comma-change").html(".");
});
<span class="tick">2,354,456</span>
因此,而不是增加1个在增量领域,我想编写一个随机数更新的功能。与其他职位的帮助下,我可以写一个产生一个随机数没有问题的功能:
function random_generator (min, max) {
return Math.random() * (max - min) + min;
}
,但我有麻烦直接合作成这样。
这里是插件的增量部分:
Tick = (function() {
function Tick(element, options) {
this.element = element;
if (options == null) options = {};
this.running = false;
this.options = {
delay: options.delay || 1000,
separators: options.separators != null ? options.separators : false,
autostart: options.autostart != null ? options.autostart : true
};
this.increment = this.build_increment_callback(options.incremental);
this.value = Number(this.element.html().replace(/[^\d.]/g, ''));
this.separators = this.element.html().trim().split(/[\d]/i);
this.element.addClass('tick-active');
if (this.options.autostart) this.start();
}
Tick.prototype.build_increment_callback = function(option) {
if ((option != null) && {}.toString.call(option) === '[object Function]') {
return option;
} else if (typeof option === 'number') {
return function(val) {
return val + option;
};
} else {
return function(val) {
return val + 1;
};
}
};
,然后该位:
Tick.prototype.tick = function() {
this.value = this.increment(this.value);
this.render();
return this.set_timer();
};
你需要直接更新增量脚本..你有代码在哪里使用'incremental'? –
是的,代码的增量部分添加到原始问题 – absentx