简易滚动数字

一、前言

没什么好说的

二、代码

<template>
  <div class="flex">
    <div class="w-36px h-36px overflow-hidden border border-gray-600 mx-3px" v-for="(item1,index1) in basevalue"
         :key="index1 + 'base'">
      <div class="w-36px h-36px leading-36px text-center text-xl select-none" :class="[classlist[index1]]"
           :style="{transform:`translateY(-${item1*36}px)`}" v-for="item2 in shuzi" :key="item2+'a'">{{ item2 }}
      </div>
    </div>
  </div>
</template>

<script setup>
import {ref, onMounted, defineEmits, defineProps, nextTick, watch, computed} from "vue"
import {useRoute, useRouter} from "vue-router";
import {useStore} from "vuex";

const router = useRouter()
const route = useRoute()
const store = useStore()
const basevalue = ref(["0", "0", "0", "0", "0", "0"])
const shuzi = ref(["0", "1", "2", "3", "4", "5", "6", "7", "8", "9",])
const classlist = ref([])
const xunhuan1 = ref(null)
const xunhuan2 = ref(null)
const props = defineProps({
  num: {
    type: Number || String,
    default: 0 || "0",
  },
})
watch(() => props.num, () => {
  console.log("触发方法")
  basevalue.value = props.num.toString().split("")
  bianbianbian()
  console.log(classlist.value, "有没有啊")
})
const bianbianbian = () => {
  clearTimeout(xunhuan1.value)
  clearTimeout(xunhuan2.value)
  classlist.value = []
  basevalue.value.forEach((item, index) => {
    classlist.value[index] = "gundong"
  })
  xunhuan1.value = setTimeout(() => {
    tingzhi()
  }, 2000)
}
const tingzhi = () => {
  for (let i = 0; i < basevalue.value.length; i++) {
    if (classlist.value[i] === "gundong") {
      classlist.value[i] = ""
      break;
    }
  }
  if(classlist.value.includes("gundong")){
    xunhuan2.value = setTimeout(() => {
      tingzhi()
    }, 1000)
  }
}
</script>
<script>
import {defineComponent} from "vue"

export default defineComponent({
  name: "",
})
</script>

<style scoped>
.gundong {
  animation: gundonganimation 0.8s infinite linear;
}

@keyframes gundonganimation {
  0% {
    transform: translateY(18px);
  }
  50% {
    transform: translateY(-180px)
  }
  100% {
    transform: translateY(-360px)
  }
}
</style>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值