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. java-web中的Filter&Listener

    Filter过滤器 当访问服务器资源的时候,过滤器可以将i气你个球拦截下来,完成一些特殊的功能 过滤器的作用: 一般用于完成通用的操作,如验证登陆,统一的编码处理,敏感字符过滤.就是打游戏骂人,会出现 ...

  2. Effective Java —— 多字段下考虑使用建造者模式构建实例

    本文参考 本篇文章参考自<Effective Java>第三版第二条"Consider a builder when faced with many constructor pa ...

  3. C++ | 智能指针初探

    智能指针初探 在 c/c++ 语言中有一种特殊的类型--指针类型. 指针作为实体,是一个用来保存一个内存地址的计算机语言中的变量.它可以直接对内存地址中的数据进行操作,是一种非常灵活的变量.指针被誉为 ...

  4. Centos7 离线安装 KVM,并安装 Csr1000v

    最近需要在客户环境搭建 csr1000v,客户环境不能联网,同时使用 kvm 管理.所以需要离线安装 kvm,在利用 kvm 安装 csr100v ,中间遇到不少坑,现记录如下. 所有安装步骤是在 r ...

  5. 基于vue2.0的在线电影APP,

    基于vue2.0构建的在线电影网[film],webpack + vue + vuex + vue-loader + keepAlive + muse-ui + cordova 全家桶,cordova ...

  6. 7步学会在Windows下上架iOS APP流程

    之前用跨平台开发工具做了一个应用,平台可以同时生成安卓版和苹果版,想着也把这应用上架到App Store试试,于是找同学借了个苹果开发者账号,但没那么简单,还要用到Mac电脑的钥匙串申请发布证书和上传 ...

  7. Mybatis 多表实现多对多查询、添加操作

    Mybatis 多表实现多对多查询.添加操作 学习内容: 1. 多对多之添加操作 1.1.需求 1.2.数据库表(多对多数据库设计需要设计中间表) 1.3.类设计 1.4.Mapper 接口和 Map ...

  8. maven安装和配置阿里云镜像(各种详细配置)

    maven安装和详细配置 提示:下面是maven3.6.3版本百度云链接,记住maven3.3以上版本必须安装jdk1.7及以上版本,否则会出错. 链接:https://pan.baidu.com/s ...

  9. apache开启图片缓存压缩

    ①-浏览器缓存图片信息 开启Apache的expires模块,重启Apache 2.在虚拟主机的配置文件里面,增加对图片信息缓存的配置,重启Apache 3.在网站目录里面填写测试代码 4.测试效果 ...

  10. nodejs全局对象简析

    Global:全局变量 定时器.控制台输出.事件 模块化相关的一些全局变量 path/url相关的一些全局变量 编码相关的 buffer:缓存(简单介绍) Process:进程(重点解析) 一.Glo ...