jquery实现数字滚动特效
一、引入js文件
<script src="https://code.jquery.com/jquery-3.3.1.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/1.20.4/TweenLite.min.js"></script>
<script src="lem_counter.js"></script>
lem_counter.js文件源码
/******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId]) {
/******/ return installedModules[moduleId].exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ i: moduleId,
/******/ l: false,
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded
/******/ module.l = true;
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/
/******/ // define getter function for harmony exports
/******/ __webpack_require__.d = function(exports, name, getter) {
/******/ if(!__webpack_require__.o(exports, name)) {
/******/ Object.defineProperty(exports, name, {
/******/ configurable: false,
/******/ enumerable: true,
/******/ get: getter
/******/ });
/******/ }
/******/ };
/******/
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = function(module) {
/******/ var getter = module && module.__esModule ?
/******/ function getDefault() { return module['default']; } :
/******/ function getModuleExports() { return module; };
/******/ __webpack_require__.d(getter, 'a', getter);
/******/ return getter;
/******/ };
/******/
/******/ // Object.prototype.hasOwnProperty.call
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(__webpack_require__.s = 0);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
/*Version: 1.0.0Author: lemehovskiyWebsite: http://lemehovskiy.github.ioRepo: https://github.com/lemehovskiy/lem_counter*/var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }(function ($) {var LemCounter = function () {function LemCounter(element, options) {_classCallCheck(this, LemCounter);var self = this;//extend by function callself.settings = $.extend(true, {value_from: 0,value_to: 0,locale: false,value_to_from_content: false,animate_duration: 2}, options);self.$element = $(element);self.to_fixed_digits = 0;//extend by data optionsself.data_options = self.$element.data('lem-counter');self.settings = $.extend(true, self.settings, self.data_options);//value to from contentif (self.settings.value_to_from_content) {//check if number and remove commasif (!isNaN(self.$element.text().replace(/,/g, ''))) {self.settings = $.extend(true, self.settings, {value_to: Number(self.$element.text().replace(/,/g, ''))});}}//set start valueself.counter_helper = { val: self.settings.value_from };self.init();}_createClass(LemCounter, [{key: 'init',value: function init() {var self = this;var counter_to = self.settings.value_to;//check if number is floatif (isFloat(counter_to)) {var string_counter_val_to = counter_to.toString();self.to_fixed_digits = string_counter_val_to.substr(string_counter_val_to.indexOf('.') + 1).length;}TweenLite.to(self.counter_helper, self.settings.animate_duration, {val: counter_to,onUpdate: updateHandler,ease: Linear.easeNone,onComplete: function onComplete() {self.$element.trigger('onComplete.lc');}});function isFloat(n) {return Number(n) === n && n % 1 !== 0;}function updateHandler() {var value = self.counter_helper.val;var num = value.toFixed(self.to_fixed_digits);var num_locale = 0;if (self.to_fixed_digits == 0) {num_locale = parseInt(num);} else {num_locale = parseFloat(num);}if (self.settings.locale) {num_locale = num_locale.toLocaleString(self.settings.locale, { maximumFractionDigits: self.to_fixed_digits });}self.$element.text(num_locale);}}}]);return LemCounter;}();$.fn.lemCounter = function () {var $this = this,opt = arguments[0],args = Array.prototype.slice.call(arguments, 1),length = $this.length,i = void 0,ret = void 0;for (i = 0; i < length; i++) {if ((typeof opt === 'undefined' ? 'undefined' : _typeof(opt)) == 'object' || typeof opt == 'undefined') $this[i].lem_counter = new LemCounter($this[i], opt);else ret = $this[i].lem_counter[opt].apply($this[i].lem_counter, args);if (typeof ret != 'undefined') return ret;}return $this;};
})(jQuery);/***/ })
/******/ ]);
二、创建一个要显示动画计数器的容器
<div class="myCounter"></div>
三、实现数字滚动特效
1、调用容器元素上的函数并指定要计数的目标编号
$('.myCounter').lemCounter({value_to: 100
});
2、指定要倒计时的值
$('.myCounter').lemCounter({value_to: 100,value_from: 500
});
3、可以直接在容器元素中指定目标编号
$('.myCounter').lemCounter({value_to_from_content: true
});<div class="myCounter">100</div>
4、使用data属性配置动画计数器
$('.myCounter').lemCounter();<div class="myCounter"data-lem-counter='{"value_from": 200, "value_to": 100'>
</div>
5、所有默认配置选项
$('.myCounter').lemCounter({value_from: 0, //起始值value_to: 0, //终值locale: false, // e.g. 'en-US' //英美数字表示法 例如:1,230value_to_from_content: false,animate_duration: 2
});
转自: https://www.jqueryscript.net/animation/Animated-Counter-jQueryGSAP-Lem-Counter.html
https://blog.csdn.net/qq_29777207/article/details/85172376
http://www.17sucai.com/pins/demo-show?id=28195
jquery实现数字滚动特效相关推荐
- jquery 数字滚动特效 数字自增特效 数字位数动态适应
最近做了个大项目,需要在首页动画显示实时统计数据,虽然百度了不少jquery特效,但有的需要积分,有的功能不全面,下面我将源码分享出来. html <!DOCTYPE html> < ...
- html数字滚动动画效果,高效的jquery数字滚动特效
本文实例讲述了基于jquery数字滚动特效的代码,分为四种情况分享给大家供大家参考,具体如下: 有分隔符,有小数点: 只有分隔符: 只有小数点: 无分隔符,无小数点: 运行效果图: 具体代码如下 数字 ...
- jQuery图标数字滚动计数代码
jQuery图标数字滚动计数代码 jQuery基于css3属性制作图标和数字结合布局,默认数字滚动计数效果代码. 演示地址 下载地址
- css3数字滚动特效简单实现
放在大屏里面的数字滚动特效的简单实现, 思路参考:https://blog.csdn.net/nidunlove/article/details/78257549 结合业务需求和自己的思考拿vue写了 ...
- h5 数字变化_那些H5用到的技术(6)——数字滚动特效
前言 会有这么一种情况,H5页面需要进行数字统计展示,以此来强调产品or工作的成果.如果只是静态显示一个数字,总是感觉生硬.对比如下: 是不是瞬间高大上了呢? 这个效果我是在开源中国上找到的 http ...
- js、jQuery实现数字滚动效果
一.效果(监听页面滚动使得超过屏幕的数字每次出现都有数字滚动效果) 二.代码 在滚动数字的标签上加上类名counter <div class="about_right flex5&qu ...
- jquery实现数字滚动效果
因为需要,自己用jquery动手写了数字滚动效果 实现原理 1.先确定数字最大的位数,比如说最大数为6位数,就画出一排6个高度为30px的方格; 2.然后在每个方格区域增加一竖排的 012345678 ...
- html数字滚动选择,js实现数字滚动特效
本文实例为大家分享了js实现数字滚动展示的具体代码,供大家参考,具体内容如下 效果图 html代码 Title #t,#tt{ border: #ccc thin solid; width: 250p ...
- vue3 | 数据可视化实现数字滚动特效
前言 vue3不支持vue-count-to插件,无法使用vue-count-to实现数字动效,数字自动分割,vue-count-to主要针对vue2使用,vue3按照会报错: TypeError: ...
最新文章
- python文本分类特征选择_文本挖掘之特征选择(python 实现)
- 屏显有啥硬科技可卷?让现在电视厂商这么拼
- python信号处理教程_python 之信号Signal|python3教程|python入门|python教程
- 智能快递柜10月1日起按新规管理
- 裸板烧写linux内核,嵌入式linux学习(二):烧写裸板进程
- android studio刷rom,Android Studio 之 ROM【1】, Entity,Dao,Database
- linux vim 终端 行首 行尾_不会vi/vim,看这一篇足矣
- php中smarty扩展类问题
- 药店管理系统/APP/小程序/网站
- html中怎么写行内样式,css行内样式是什么?
- python按照绝对值排序_尝试使用python中的绝对值,按最接近零的值对列表进行排序...
- [爬虫项目]猫眼电影TOP100
- 我的世界java出生蘑菇岛,我的世界:有出生蘑菇岛和要塞的超大村庄?这超富有种子满足你!...
- get查询IP PHP源码,ip归属地查询代码
- 华为服务器jbod修改启动项,服务器设置jbod
- Kubernetes监控:Dashbaord 2.0.0部署之证书创建和设定
- 哔哩哔哩轻视频怎么去水印
- 南卡和OPPO蓝牙耳机哪个更好?高性价比蓝牙耳机评测
- git fetch批处理,遍历一个文件夹下的所有子目录,执行git fetch --all
- 【敏捷开发每日一贴】DoD“完成”的定义