您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

vue 实现数字滚动增加效果

2024/6/17 5:49:40发布35次查看
这篇文章主要介绍了关于vue 实现数字滚动增加效果 ,有着一定的参考价值,现在分享给大家,有需要的朋友可以参考一下
项目中需要做数字滚动增加的效果,一开始很懵,研究了一下原理,发现很简单,贴出来分享一下 ^_^
数字滚动组件:
<template><p class="number-grow-warp">  <span ref="numbergrow" :data-time="time" class="number-grow" :data-value="value">0</span>  </p></template><script>export default {  props: {    time: {      type: number,      default: 2    },    value: {      type: number,      default: 720000    }  },  methods: {    numbergrow (ele) {      let _this = this      let step = (_this.value * 10) / (_this.time * 1000)      let current = 0      let start = 0      let t = setinterval(function () {        start += step        if (start > _this.value) {          clearinterval(t)          start = _this.value          t = null        }        if (current === start) {          return        }        current = start        ele.innerhtml = current.tostring().replace(/(\d)(?=(?:\d{3}[+]?)+$)/g, '$1,')      }, 10)    }  },  mounted () {    this.numbergrow(this.$refs.numbergrow)  }}</script><style>.number-grow-warp{  transform: translatez(0);}.number-grow {  font-family: arial-boldmt;  font-size: 64px;  color: #ffaf00;  letter-spacing: 2.67px;  margin:110px 0 20px;  display: block;  line-height:64px;}</style>
调用:
<numbergrow :value="720000"></numbergrow>
以上就是本文的全部内容,希望对大家的学习有所帮助,更多相关内容请关注!
相关推荐:
vue的父子组件,父子组件传值和vuex的浅析
利用javascript判断浏览器类型
以上就是vue 实现数字滚动增加效果的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product