话不多少,主要是自己记录下以便后期查看templatediv class=chartNumdiv class=box-itemli :class={number-item: !isNaN(item), mark-item: isNaN(item) }v-for=(item,index) in orderNum:key=...
话不多少,主要是自己记录下以便后期查看
<template>
<div class="chartNum">
<div class="box-item">
<li :class="{'number-item': !isNaN(item), 'mark-item': isNaN(item) }"
v-for="(item,index) in orderNum"
:key="index">
<span v-if="!isNaN(item)">
<i ref="numberItem">0123456789</i>
</span>
<span class="comma" v-else>{{item}}</span>
</li>
</div>
</div>
</template>
<script>
export default {
data() {
return {
orderNum: [ '0', '0','.', '0', '0'],
}
},
mounted() {
this.toOrderNum(12.35) // 这里输入数字即可调用
this.setNumberTransform()
setTimeout(() => {
this.toOrderNum(12.28)
this.setNumberTransform()
}, 2000);
},
methods: {
// 设置文字滚动
setNumberTransform() {
const numberItems = this.$refs.numberItem // 拿到数字的ref,计算元素数量
const numberArr = this.orderNum.filter(item => !isNaN(item))
// 结合CSS 对数字字符进行滚动,显示金额
for (let index = 0; index < numberItems.length; index++) {
const elem = numberItems[index]
elem.style.transform = `translate(-50%, -${numberArr[index] * 10}%)`
}
},
// 处理总金额
toOrderNum(num) {
console.log('11111')
num = num.toString()
console.log(num.length)
if (num.length === 5) {
this.orderNum = num.split('') // 将其变成数据,渲染至滚动数组
console.log(this.orderNum,'this.orderNum')
}
},
},
}
</script>
<style lang='less'>
/*金额滚动数字设置*/
.box-item {
width: 100%;
text-align: center;
line-height: 40px;
font-size: 24px;
padding: 2% 0;
position: relative;
list-style: none;
writing-mode: vertical-lr;
text-orientation: upright;
/*文字禁止编辑*/
-moz-user-select: none; /*火狐*/
-webkit-user-select: none; /*webkit浏览器*/
-ms-user-select: none; /*IE10*/
-khtml-user-select: none; /*早期浏览器*/
user-select: none;
}
/* 默认逗号设置 */
.mark-item {
width: 10px;
line-height: 10px;
font-size: 24px;
position: relative;
}
.mark-item span {
position: absolute;
width: 100%;
bottom: 0;
writing-mode: vertical-rl;
text-orientation: upright;
}
/*滚动数字设置*/
.number-item {
width: 20px;
height: 30px;
list-style: none;
margin-right: 5px;
background-size: 100% 100%;
}
.number-item:first-child {
margin-left: 0;
}
.number-item span {
position: relative;
display: inline-block;
margin-right: 10px;
width: 100%;
height: 100%;
writing-mode: vertical-rl;
text-orientation: upright;
overflow: hidden;
}
.number-item span i {
font-style: normal;
position: absolute;
top: 0px;
left: 50%;
transform: translate(-50%,0);
transition: transform .5s ease-in-out;
letter-spacing: 10px;
}
.number-item:last-child {
margin-right: 0;
}
</style>
沃梦达教程
本文标题为:vue实现 金额数字单个上下滚动切换
基础教程推荐
猜你喜欢
- Javascript Bootstrap的网格系统,导航栏和轮播详解 2023-08-11
- 关于Ajax跨域问题及解决方案详析 2023-02-23
- 在实战中可能碰到的几种ajax请求方法详解 2023-02-01
- Ajax发送和接收请求 2022-12-15
- JS滚动到顶部踩坑解决记录 2023-07-10
- Ajax+smarty技术实现无刷新分页 2022-12-15
- cocos creator游戏实现loading加载页面,游戏启动加载动画 2022-10-29
- uniapp开发微信小程序自定义顶部导航栏功能实例 2022-10-21
- HTML clearfix清除浮动讲解 2022-11-20
- 使用ajax跨域调用springboot框架的api传输文件 2023-02-23