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>

相关推荐
墨渊君1 分钟前
“蒙”出花样!用 CSS Mask 实现丝滑视觉魔法
前端·css
huabuyu32 分钟前
基于 React + MarkdownIt 的 Markdown 渲染器实践:支持地图标签和长按复制
前端
芦苇Z34 分钟前
HTML <a> 标签的 rel 属性全解析:安全、隐私与 SEO 最佳实践
前端·html
在这儿不行38 分钟前
Android 15边到边模式
前端
源猿人41 分钟前
企业级文件浏览系统的Vue实现:架构设计与最佳实践
前端·javascript·数据可视化
红红大虾41 分钟前
Defold引擎中关于CollectionProxy的使用
前端·游戏开发
最后一个农民工1 小时前
vue3实现仿豆包模版式智能输入框
前端·vue.js
RoyLin1 小时前
TypeScript设计模式:迭代器模式
javascript·后端·node.js
xw51 小时前
uni-app中v-if使用”异常”
前端·uni-app