Javascript 进度条仅加载5的倍数
出于某种原因,只有当数据分数中的数字是5的倍数时,此脚本才会工作。你知道怎么改变吗 代码: 顺便说一句,这是用bootstrap实现的 进度条只加载数字(最后一行) 动画枚举器:Javascript 进度条仅加载5的倍数,javascript,jquery,twitter-bootstrap,Javascript,Jquery,Twitter Bootstrap,出于某种原因,只有当数据分数中的数字是5的倍数时,此脚本才会工作。你知道怎么改变吗 代码: 顺便说一句,这是用bootstrap实现的 进度条只加载数字(最后一行) 动画枚举器: /*********** Animates element's number to new number with commas Parameters: stop (number): number to stop on commas (boolean): turn com
/***********
Animates element's number to new number with commas
Parameters:
stop (number): number to stop on
commas (boolean): turn commas on/off (default is true)
duration (number): how long in ms (default is 1000)
ease (string): type of easing (default is "swing", others are avaiable from jQuery's easing plugin
Examples:
$("#div").animateNumbers(1234, false, 500, "linear"); // half second linear without commas
$("#div").animateNumbers(1234, true, 2000); // two second swing with commas
$("#div").animateNumbers(4321); // one second swing with commas
This fully expects an element containing an integer
If the number is within copy then separate it with a span and target the span
Inserts and accounts for commas during animation by default
***********/
(function($) {
$.fn.animateNumbers = function(stop, commas, duration, ease) {
return this.each(function() {
var $this = $(this);
var start = parseInt($this.text().replace(/,/g, ""));
commas = (commas === undefined) ? true : commas;
$({value: start}).animate({value: stop}, {
duration: duration == undefined ? 1000 : duration,
easing: ease == undefined ? "swing" : ease,
step: function() {
$this.text(Math.floor(this.value));
if (commas) { $this.text($this.text().replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,")); }
},
complete: function() {
if (parseInt($this.text()) !== stop) {
$this.text(stop);
if (commas) { $this.text($this.text().replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,")); }
}
}
});
});
};
})(jQuery);
什么是
animateNumbers
?您使用的是旧版本的jquery吗datascore=me.attr('data-score')
是我使用的最新引导版本的变通方法。我用animateNumbers更新了帖子。animateNumbers插件可能需要一些帮助:(我重写了其中的一部分并提交了一个pull请求。parseInt没有设置基本参数存在一些问题,还有一些性能问题,比如每次迭代都要多次设置文本(DOM每次都会刷新)。
/***********
Animates element's number to new number with commas
Parameters:
stop (number): number to stop on
commas (boolean): turn commas on/off (default is true)
duration (number): how long in ms (default is 1000)
ease (string): type of easing (default is "swing", others are avaiable from jQuery's easing plugin
Examples:
$("#div").animateNumbers(1234, false, 500, "linear"); // half second linear without commas
$("#div").animateNumbers(1234, true, 2000); // two second swing with commas
$("#div").animateNumbers(4321); // one second swing with commas
This fully expects an element containing an integer
If the number is within copy then separate it with a span and target the span
Inserts and accounts for commas during animation by default
***********/
(function($) {
$.fn.animateNumbers = function(stop, commas, duration, ease) {
return this.each(function() {
var $this = $(this);
var start = parseInt($this.text().replace(/,/g, ""));
commas = (commas === undefined) ? true : commas;
$({value: start}).animate({value: stop}, {
duration: duration == undefined ? 1000 : duration,
easing: ease == undefined ? "swing" : ease,
step: function() {
$this.text(Math.floor(this.value));
if (commas) { $this.text($this.text().replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,")); }
},
complete: function() {
if (parseInt($this.text()) !== stop) {
$this.text(stop);
if (commas) { $this.text($this.text().replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,")); }
}
}
});
});
};
})(jQuery);