css3数字滚动特效

一个格子:
效果:
在这里插入图片描述

代码:

props:['value'],
data(){
	return {
		pretime: undefined,
	    numbers:[0,0,0,0,0,0],
	    numLenth:0,
	}
},
 created () {
    setTimeout(()=>{
      this.number = this.value
    },500)
  },
<template>
  <div class="chartNum">
    <div class="box-item">
        <li :class="['number-item', 'mark-item']">
          <span v-if="value">
            <i ref="numberItem" :style="{transform:`translate(-50%, -${number * 10}%)`}">0123456789</i>
          </span>
          <span class="comma" v-else>{{number}}</span>
        </li>
    </div>
  </div>
</template>
<style scoped lang='scss'>
    .box-item {
        position: relative;
        height:35px;
        font-size: 54px;
        line-height: 41px;
        text-align: center;
        list-style: none;
        color: rgb(255,255,0);
        writing-mode: vertical-lr;
        text-orientation: upright;
        /*文字禁止编辑*/
        -moz-user-select: none; /*火狐*/
        -webkit-user-select: none; /*webkit浏览器*/
        -ms-user-select: none; /*IE10*/
        -khtml-user-select: none; /*早期浏览器*/
        user-select: none;
        /* overflow: hidden; */
    }
    /*滚动数字设置*/
    .number-item {
        list-style: none;
        width: 35px;
        height: 35px;
        background-image: url('/static/img/image/数字框1.jpg');
        background-size:100% 100% ;
        margin-right: 3px;
        color: rgb(255,255,0);
        font-weight: bold;
        display: flex;
        justify-content: center;
        align-items: center;
        font-size: 22px;
        & > span {
            position: relative;
            display: block;
            width: 100%;
            height: 100%;
            writing-mode: vertical-rl;
            text-orientation: upright;
            overflow: hidden;
            & > i {
                font-style: normal;
                position: absolute;
                top: 5px;
                left: 50%;
                transition:transform 2s ease-in-out;
                transform: translate(-50%,0);
                letter-spacing: 10px;
            }
        }
        .comma{
          text-align: center;
          padding-left: 5px;
        }
    }
    .number-item:last-child {
        margin-right: 0;
    }
</style>

多个格子:
效果:
每个格子里的数字,如果大于0就会从0向上滚动到数字的位置
在这里插入图片描述

代码:

//因为是组件
props:['value'],
data(){
	return {
		pretime: undefined,
	    numbers:[0,0,0,0,0,0],
	    numLenth:0,
	}
},
computed:{
	_value:{
    get(){
      let arr = []
      this.numLenth = String(this.value).length
      if(this.value){
        for(var i = 0 ;i<this.numLenth;i++){
          arr.push(String(this.value).substr(i,1))
        }
      }
      if(arr.length<6){
        let len = 6-arr.length
        for(var j = 0;j<len;j++){
          arr.unshift(0)
        }
      }else{
        arr = arr.splice(0,6)
      }
      return arr
    }
  }
}

created () {
    setTimeout(()=>{
      let Arr =  this._value
      for(var i=0;i<Arr.length;i++){
        this.numbers[i] = Arr[i]
      }
      this.numbers = this.numbers.concat([])
    },500)
  },
<template>
  <div class="chartNum">
    <div class="box-item">
        <li :class="['number-item', 'mark-item']" v-for="(number,index) in _value" :key="index">
          <span v-if="number">
            <i ref="numberItem" :style="{transform:`translate(-50%, -${numbers[index] * 10}%)`}">0123456789</i>
          </span>
          <span class="comma" v-else>{{number}}</span>
        </li>
    </div>
  </div>
</template>

<style scoped lang='scss'>
    .box-item {
        position: relative;
        height:33px;
        font-size: 54px;
        line-height: 41px;
        text-align: center;
        list-style: none;
        color: rgb(255,255,0);
        writing-mode: vertical-lr;
        text-orientation: upright;
        /*文字禁止编辑*/
        -moz-user-select: none; /*火狐*/
        -webkit-user-select: none; /*webkit浏览器*/
        -ms-user-select: none; /*IE10*/
        -khtml-user-select: none; /*早期浏览器*/
        user-select: none;
        /* overflow: hidden; */
    }
    /*滚动数字设置*/
    .number-item {
        list-style: none;
        width: 33px;
        height: 33px;
        background-image: url('/static/img/image/数字框1.jpg');
        background-size:100% 100% ;
        margin-right: 3px;
        color: rgb(255,255,0);
        font-weight: bold;
        display: flex;
        justify-content: center;
        align-items: center;
        font-size: 22px;
        & > span {
            position: relative;
            display: inline-block;
            width: 100%;
            height: 100%;
            writing-mode: vertical-rl;
            text-orientation: upright;
            overflow: hidden;
            & > i {
                font-style: normal;
                position: absolute;
                top: 5px;
                left: 50%;
                transition:transform 1s ease-out;
                transform: translate(-50%,0);
                letter-spacing: 10px;
            }
        }
        .comma{
          padding-left: 7px;
          padding-top: 3px;
        }
    }
    .number-item:last-child {
        margin-right: 0;
    }
</style>
  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

_小郑有点困了

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值