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>

相关推荐
漫路在线27 分钟前
JS逆向-某易云音乐下载器
开发语言·javascript·爬虫·python
不爱吃糖的程序媛30 分钟前
浅谈前端架构设计与工程化
前端·前端架构设计
BillKu2 小时前
Vue3 Element Plus 对话框加载实现
javascript·vue.js·elementui
郝YH是人间理想2 小时前
系统架构设计师案例分析题——web篇
前端·软件工程
Evaporator Core2 小时前
深入探索:Core Web Vitals 进阶优化与新兴指标
前端·windows
初遇你时动了情3 小时前
html js 原生实现web组件、web公共组件、template模版插槽
前端·javascript·html
QQ2740287563 小时前
Soundness Gitpod 部署教程
linux·运维·服务器·前端·chrome·web3
前端小崔3 小时前
从零开始学习three.js(18):一文详解three.js中的着色器Shader
前端·javascript·学习·3d·webgl·数据可视化·着色器
哎呦你好3 小时前
HTML 表格与div深度解析区别及常见误区
前端·html
运维@小兵4 小时前
vue配置子路由,实现点击左侧菜单,内容区域显示不同的内容
前端·javascript·vue.js