html

<div class="timer" data-to="633"></div>
<div class="timer" data-from="32" data-to="12456"></div>
<script src="../jquery-3.1.0.min.js"></script>
<script src="jquery.countTo.js"></script>
<script>
$(function() {
$(".timer").countTo();
});
</script>

jquery.countTo.js

(function (factory) {
if (typeof define === 'function' && define.amd) {
// AMD
define(['jquery'], factory);
} else if (typeof exports === 'object') {
// CommonJS
factory(require('jquery'));
} else {
// Browser globals
factory(jQuery);
}
}(function ($) {
var CountTo = function (element, options) {
this.$element = $(element);
this.options = $.extend({}, CountTo.DEFAULTS, this.dataOptions(), options);
this.init();
}; CountTo.DEFAULTS = {
from: 0, // the number the element should start at
to: 0, // 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
formatter: formatter, // handler for formatting the value before rendering
onUpdate: null, // callback method for every time the element is updated
onComplete: null // callback method for when the element finishes updating
}; CountTo.prototype.init = function () {
this.value = this.options.from;
this.loops = Math.ceil(this.options.speed / this.options.refreshInterval);
this.loopCount = 0;
this.increment = (this.options.to - this.options.from) / this.loops;
}; CountTo.prototype.dataOptions = function () {
var options = {
from: this.$element.data('from'),
to: this.$element.data('to'),
speed: this.$element.data('speed'),
refreshInterval: this.$element.data('refresh-interval'),
decimals: this.$element.data('decimals')
}; var keys = Object.keys(options); for (var i in keys) {
var key = keys[i]; if (typeof(options[key]) === 'undefined') {
delete options[key];
}
} return options;
}; CountTo.prototype.update = function () {
this.value += this.increment;
this.loopCount++; this.render(); if (typeof(this.options.onUpdate) == 'function') {
this.options.onUpdate.call(this.$element, this.value);
} if (this.loopCount >= this.loops) {
clearInterval(this.interval);
this.value = this.options.to; if (typeof(this.options.onComplete) == 'function') {
this.options.onComplete.call(this.$element, this.value);
}
}
}; CountTo.prototype.render = function () {
var formattedValue = this.options.formatter.call(this.$element, this.value, this.options);
this.$element.text(formattedValue);
}; CountTo.prototype.restart = function () {
this.stop();
this.init();
this.start();
}; CountTo.prototype.start = function () {
this.stop();
this.render();
this.interval = setInterval(this.update.bind(this), this.options.refreshInterval);
}; CountTo.prototype.stop = function () {
if (this.interval) {
clearInterval(this.interval);
}
}; CountTo.prototype.toggle = function () {
if (this.interval) {
this.stop();
} else {
this.start();
}
}; function formatter(value, options) {
return value.toFixed(options.decimals);
} $.fn.countTo = function (option) {
return this.each(function () {
var $this = $(this);
var data = $this.data('countTo');
var init = !data || typeof(option) === 'object';
var options = typeof(option) === 'object' ? option : {};
var method = typeof(option) === 'string' ? option : 'start'; if (init) {
if (data) data.stop();
$this.data('countTo', data = new CountTo(this, options));
} data[method].call(data);
});
};
}));

网页数字递增——jquery.countTo.js的更多相关文章

  1. js 数字递增特效 仿支付宝我的财富 HTML5

    上周五应着公司临时需求,一天的时间解决掉官网(ps:比较简单哈哈),需求里面有一个特效就是数字递增到指定的数值,其实JS写也不复杂的,但是我发现一个js小插件,这个插件轻巧简单,用起来也非常简单实用. ...

  2. js-数字渐增到指定的数字,在指定的时间内完成(有动画效果哦)插件jquery.animateNumber.js

    本来在项目中我自己实现的效果是数字由0渐增到指定的数字就好. 但是,最终效果不理想! Why? 最终指定的数字太大了,TMMD,滚动好久就不到,那用户想看自己有多少钱了,那不是就一直等着!!!所以这个 ...

  3. js验证连续两位数字递增或递减和连续三位数字相同

    <!DOCTYPE html><html><head lang="en"> <meta charset="UTF-8" ...

  4. 使用jquery.PrintArea.js打印网页的样式问题

    在使用jquery.PrintArea.js打印局部网页样式的时候,发现样式打印不出来,在网上找了好多资料,整理一下分享给大家 一.先看看css的引用文件方式 1.直接在内部的元素中使用”style” ...

  5. 好用的jquery.animateNumber.js数字动画插件

    在做公司的运营报告页面时,有一个数字累计增加的动画效果,一开始,毫无头绪,不知如何下手,于是上网查资料,发现大多都是用的插件来实现的,那么今天,我也来用插件jquery.animateNumber.j ...

  6. jquery轻量级数字动画插件jquery.countup.js

    插件描述: jquery.countup.js 是一款轻量级jquery数字动画插件.该数字动画插件可以在页面滚动时,将指定的数字从0开始计数增加动画. 插件说明 jquery.countup.js  ...

  7. 使用jquery.layout.js构建页眉/页脚/左侧导航/中间展示内容的网页结构

    背景: 快速将一个页面分成几个部分,在导航和页眉的位置放置公用的元素. 准备: jquery.layout.js 首先,向页面中引入如下js文件和css文件,代码: <link href=&qu ...

  8. <<< 网页中如何利用原生js和jquery储存cookie

    javascript当中的cookie机制,使应用达到了真正的全局变量的要求,cookie是浏览器提供的一种机制,它将document 对象的cookie属性提供给JavaScript.可以由Java ...

  9. html5网页动画总结--jQuery旋转插件jqueryrotate

    CSS3 提供了多种变形效果,比如矩阵变形.位移.缩放.旋转和倾斜等等,让页面更加生动活泼有趣,不再一动不动.然后 IE10 以下版本的浏览器不支持 CSS3 变形,虽然 IE 有私有属性滤镜(fil ...

随机推荐

  1. innodb和myisam

    在Mysql数据库中,常用的引擎主要就是2个:Innodb和MyIASM.这篇文章将主要介绍这两个引擎,以及该如何去选择引擎,最后在提一下这2种引擎所使用的数据结构是什么. 首先介绍一下Innodb引 ...

  2. Effective Java —— 避免创建不必要的对象

    本文参考 本篇文章参考自<Effective Java>第三版第六条"Avoid creating unnecessary objects" avoid creatin ...

  3. C语言对源程序处理的四个步骤:预处理、编译、汇编、链接——预处理篇

    预处理 1)预处理的基本概念 C语言对源程序处理的四个步骤:预处理.编译.汇编.链接. 预处理是在程序源代码被编译之前,由预处理器(Preprocessor)对程序源代码进行的处理.这个过程并不对程序 ...

  4. Android项目如何打包成安装包.apk

    1.Build -> Generate Signed APK 2.APK -> Next 3.输入Key store path以及密码 ->next(如果是第一次则需要新建,新建教程 ...

  5. uniapp最简单的上拉加载更多demo

    data() { return { list:[],//数据列表 page: 1,//页数 } }, //请求一下数据(进入页面请求一次) onLoad() { this.getnewsList(th ...

  6. C语言之:结构体动态分配内存(利用结构体数组保存不超过10个学生的信息,每个学生的信息包括:学号、姓名和三门课(高数、物理和英语 )的成绩和平均分(整型)。)

    题目内容: 利用结构体数组保存不超过10个学生的信息,每个学生的信息包括:学号.姓名和三门课(高数.物理和英语 )的成绩和平均分(整型). 编写程序,从键盘输入学生的人数,然后依次输入每个学生的学号. ...

  7. Spring Boot-@ImportResource注解

    @ImportResource:导入Spring的配置文件,让配置文件里面的内容生效 第一步:创建一个spring配置文件bean.xml <?xml version="1.0&quo ...

  8. centos7源码安装mysql5.7.19

    centos7源码包安装mysql5.7 5.7.20安装方法和5.7.19的一样. 1.安装前准备 清空环境.安装相应的软件包 1>关闭防火墙和SELinux 2>配置yum源(阿里云, ...

  9. 使用 LOAD DATA LOCAL INFILE,sysbench 导数速度提升30%

    1. LOAD DATA INFILE 为什么比 INSERT 快? 2. sysbench 压测 MySQL 的四个标准步骤. 3. 怎么让 sysbench 支持 LOAD DATA LOCAL ...

  10. DRF JWT认证(一)

    为什么要使用JWT认证?构成和原理又是什么?怎么还有Base64的事?我都写了