首页

源码搜藏网

首页 > 开发教程 > js/jQuery教程 >

vue版数字翻牌器的封装

创建时间:2022-04-20 15:30  

本文实例为大家分享了vue版数字翻牌器的封装代码,供大家参考,具体内容如下

封装vue版数字翻牌器

<template>
  <div class="number">
    <ul id="dataNums">
      <li v-for="(item,index) in list" :key="index">
        <div class="dataBoc">
          <div class="tt" :style="{transition:'all 2.5s ease-in-out 0s',top:'-'+item.top+'px'}">
            <span v-for="(item2,index2) in numList" :key="index2">{{item2}}    
            </span>        
          </div>
        </div>
      </li>
    </ul>
  </div>
</template>

vue版数字翻牌器的封装

js部分

export default {
  props:{ number:Number },
  data(){
    return{
      list:[],
      numList: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, '.']
    }
  },
  mounted(){
    this.scroll();
  },
  methods:{
    scroll(){
      this.list=this.number.toString().split('');
      let arr=[];
      this.list.forEach((value) => {
        arr.push({ num:value, top:0 })
      });
      this.list=arr;
     let Hei=parseFloat(getComputedStyle(document.getElementById("dataNums")).height);      
      this.list.forEach((value,index) => {
      setTimeout(()=>{
        value.top=parseFloat((value.num*Hei)+(Hei*10)); },index*300);
      });
    }
  }
}

css样式

.number {
  margin-bottom: 10px;
  text-align: center;
  ul {
  display: inline-block;
  height: 40px;
  text-align: center;
  li {
    float: left;
    width: 40px;
    height: 40px;
    text-align: center;
    margin: 0 4px;
    background: url("../assets/images/yuyueshf/number.png") no-repeat center;//背景图          
    background-size: 100% 100%;
    .dataBoc {
      position: relative;
      width: 100%;
      height: 100%;
      overflow: hidden;
      .tt {
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        span{
        width: 100%;
        height: 100%;
        line-height: 40px;
        float: left;
        text-align: center;
        font-size: 26px;
        color: #f64841;
        }
     }
    }
   }
  }
}

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持源码搜藏网。

上一篇:vue3.0翻牌数字组件使用办法详细介绍
下一篇:没有了

相关内容

热门推荐