countup.js實現(xiàn)數(shù)字動態(tài)疊加效果
本文實例為大家分享了countup.js實現(xiàn)數(shù)字動態(tài)疊加效果的具體代碼,供大家參考,具體內(nèi)容如下
CountUp.js 無依賴的、輕量級的 JavaScript 類,可以用來快速創(chuàng)建以一種更有趣的動畫方式顯示數(shù)值數(shù)據(jù)。盡管它的名字叫 countUp,但其實可以在兩個方向進(jìn)行變化,這是根據(jù)你傳遞的 startVal 和 endVal 參數(shù)判斷的。 再加上滾輪事件判斷。
可配置的參數(shù):
- target = 目標(biāo)元素的 ID;
- startVal = 開始值;
- endVal = 結(jié)束值;
- decimals = 小數(shù)位數(shù),默認(rèn)值是0;
- duration = 動畫延遲秒數(shù),默認(rèn)值是2;
舉例:
var options = { useEasing: true, useGrouping: true, separator: ',', decimal: '.', }; var demo = new CountUp('myTargetElement', 0, 4068, 0, 2.5, options); if (!demo.error) { demo.start(); } else { console.error(demo.error);
安裝:
npm i countup.js
在vue中使用:
<template> <h1><span ref='countup' class="text" ></span> </h1> </template> <script> import { CountUp } from 'countup.js' export default { name: 'Countup', data () { return { options: { startVal: 1000 }, endCount: 2019 } }, mounted () { this.initCountUp() }, methods: { initCountUp () { let demo = new CountUp(this.$refs.countup, this.endCount, this.options) if (!demo.error) { demo.start() } else { console.error(demo.error) } } } } </script> <style lang="less" scoped> .text { color: #4d63bc; font-size: 16px; } </style>
演示地址:countUp.js
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
javascript 實現(xiàn)雙擊才能打開鏈接的方法
javascript 實現(xiàn)雙擊才能打開鏈接的方法...2007-08-08基于KO+BootStrap+MVC實現(xiàn)的分頁控件代碼分享
本段js和html兩段代碼實現(xiàn)分頁控件效果,下面通過本文給大家詳細(xì)介紹下基于KO+BootStrap+MVC實現(xiàn)的分頁控件,非常不錯,感興趣的朋友一起看看吧2016-11-11JS 對象(Object)和字符串(String)互轉(zhuǎn)方法
下面小編就為大家?guī)硪黄狫S 對象(Object)和字符串(String)互轉(zhuǎn)方法。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2016-05-05