Vue3 大屏数字滚动效果

父组件:

<template>

<div class="homePage">

<NumRoll v-for="(v, i) in numberList" :key="i" :number="v"></NumRoll>

</div>

</template>

<script setup>

import { onMounted, ref } from 'vue'

import NumRoll from '@/views/components/numRoll.vue'

const numberList = ref([0])

const number = ref(1200)

onMounted(() => {

numberList.value = number.value.toString().split('').map(item => Number(item))

setInterval(()=>{

number.value = Math.round(Math.random() * (100000 - 1000) + 1000);

numberList.value = number.value.toString().split('').map(item => Number(item))

},2000)

})

</script>

<style lang='scss' scoped>

.homePage {

padding: 10px;

display: flex;

}

</style>

子组件:

<template>

<div class="box">

<span class="num" :style="{transform: `translate(-50%, -${number * 10}%)`}">0123456789</span>

</div>

</template>

<script setup>

import { onMounted } from 'vue'

const props = defineProps({

number: {

type: Number,

default: 5,

required: true,

},

});

onMounted(() => { })

</script>

<style lang='scss' scoped>

.box {

height: 82px;

width: 54px;

line-height: 82px;

text-align: center;

background-color: #149373;

border-radius: 10px;

margin-right: 5px;

// CSS属性定义文本行是否水平或垂直布置以及块扩展的方向。

writing-mode: vertical-lr;

// 文字方向 竖直

text-orientation: upright;

position: relative;

overflow: hidden;

}

.num {

font-size: 62px;

position: absolute;

left: 50%;

top:7px;

color: #ffffff;

transition: all 1.5s;

}

</style>

相关推荐
666HZ66623 分钟前
正则表达式使用示例
javascript·vue.js·正则表达式
睡不着的可乐27 分钟前
面向对象与面向过程、函数式编程
前端·javascript·vue.js
一只小阿乐27 分钟前
前端vue3 H5实现 静态页面使用本地json 并且需要上下滑动 可以切换tabs 栏
前端·json·vue3·h5开发
欧阳天羲32 分钟前
基于 AI 的大前端安全态势感知与应急响应体系建设
前端·人工智能·安全
爱分享的程序员33 分钟前
前端面试专栏-工程化:25.项目亮点与技术难点梳理
前端·javascript·面试
YuforiaCode33 分钟前
苍穹外卖跳过支付后的来单提醒调整及相关问题解决办法
java·前端
ZHENGZJM1 小时前
使用JS编写动态表格
开发语言·前端·javascript
喝拿铁写前端1 小时前
表单设计的哲学:为何我们不再用div堆出区间组件?
前端·架构·代码规范
小彭努力中1 小时前
153.在 Vue 3 中使用 OpenLayers + Cesium 实现 2D/3D 地图切换效果
前端·javascript·vue.js·3d·ecmascript·echarts
DoraBigHead1 小时前
原型与原型链 · 千年武学秘籍终解封!
前端·javascript·面试