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>

相关推荐
几米哥几秒前
Vercel v0.app:重新定义AI驱动的全栈开发新纪元
前端
冰糖雪梨dd2 分钟前
防御XSS与CSRF攻击
前端·安全
托比-马奎尔12 分钟前
ES6变量与解构:let、const与模板字符串全解析
javascript
excel19 分钟前
JavaScript 并发编程实战:用 Atomics 与 SharedArrayBuffer 玩转多线程与视频渲染
前端
不在了情绪43 分钟前
CSS 基础语法 + 弹性盒子
前端·css
水煮白菜王1 小时前
从零搭建 React 工程化项目
前端·javascript·react.js
会飞的鱼先生1 小时前
react的基本使用
前端·react.js·前端框架
chenglin0161 小时前
C#_接口设计:角色与契约的分离
java·前端·c#
mosen8681 小时前
易混淆的CommonJS和ESM(ES Module)及它们区别
javascript·node.js·express
chenglin0161 小时前
ES_多表关联
java·前端·elasticsearch