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>

相关推荐
泯泷4 小时前
那段文字是谁删的?Yjs 14 正式版之前,一套删除归属方案的实现与边界
前端·javascript·算法
hold?fish:palm4 小时前
34 合并K个升序链表
javascript·算法·链表
野槐6 小时前
前端项目优化(有了我,会发生...)
前端
幸运小圣7 小时前
PointerEvent 常用属性与事件整理【JavaScript】
开发语言·javascript·ecmascript
aa小小7 小时前
【无标题】
前端
计算机魔术师8 小时前
还在单线程跟 AI 聊天?Claude Code 并行多会话让你一个人干三个人的活
前端
志尊宝8 小时前
Vue3 零基础每日笔记(038):亲手封装 useDebounceFn 与 useThrottleFn——高频事件的流量阀
前端·javascript·vue·html·vue3
JavaGuide8 小时前
对标 MinIO!全新一代分布式文件系统正式发布
前端·后端
风骏时光牛马8 小时前
AI驱动自动化业务工作流搭建实践
前端
码云之上9 小时前
Skill 里的脚本终于能跑了,星悟接 CubeSandbox 的纪实
前端·人工智能·前端框架