本文实例为大家分享了js实现数字变动效果展示的具体代码,供大家参考,具体内容如下
$.fn.countTo = function (options) {
options = options || {};//当options未被初始化,即typeof options = 'undefined'时,执行后面部分即var options = {}来初始化一个对象
return $(this).each(function () {
// set options for current element
var settings = $.extend({}, $.fn.countTo.defaults, {
from: $(this).data('from'),
to: $(this).data('to'),
speed: $(this).data('speed'),
refreshInterval: $(this).data('refresh-interval'),
decimals: $(this).data('decimals')
}, options);
// how many times to update the value, and how much to increment the value on each update
//更新值多少次,每次更新值多快
var loops = Math.ceil(settings.speed / settings.refreshInterval),
increment = (settings.to - settings.fro