当前位置:网站首页>数字滚动增加效果
数字滚动增加效果
2022-07-06 18:51:00 【晓_枫】
效果演示
视频演示
逻辑思路
例如我们最终要展示的数字为 5878390 ,那么第一个数字就是从1滚动到5停止,第二个数字是从0滚动到5再滚动到8停止,第三个数字是从0滚动到8再滚动到7停止(9之后是0),也就是说从左到右每一位都比前面一位滚动的时间更长,这样就出现了从左到右数字依次出现的效果。

代码实现
生成我们所需的数组
对每一位数字我们都要生成对应的数组。
this.num = '5878390'.split('');
let numArr = [];
this.num.map((item,index) => {
numArr[index] = [];
let i = 0;
// 如果不是第一次循环,要把上一次产生的数组也加进来
if(index != 0){
numArr[index] = numArr[index].concat(numArr[index - 1]);
// 取数组的最后一个赋值给 i
i = numArr[index1].pop();
}
while(i != item){
numArr[index].push(i);
i++;
// 这里取余是为了在 i 等于 10 的时候重置为 0
i = i % 10;
}
//由于判断的是 i 不等于 item, 所以最后我们把item加进来
numArr[index].push(item);
})
this.numArr = numArr; 最后生成的数组应该是这样的
html代码
代码中 numArr[indexNum].length - 1和 index == 0 ? 0 : 33 都是为了在 transform: translateY(-100%); 时正确的展示内容,这里不懂的可以在浏览器中调试css就理解了。
<div class="nums">
<div v-for="(itemNum, indexNum) in num" :key="indexNum">
// 这里通过当前下标设置不同的动画时间,根据当前数字的数组长度来设置高度,
<div
:style="{ height: numArr[indexNum].length - 1 + '00%', animationDuration: indexNum / 10 + 0.5 + 's' }">
<div v-for="(item, index) in numArr[indexNum]" :key="index"
:style="{ height: index == 0 ? 0 : 33 + 'px' }">
{
{ item }}
</div>
</div>
</div>
</div>css代码
.nums {
font-size: 26px;
font-weight: bold;
color: #FFFFFF;
line-height: 33px;
letter-spacing: 1px;
text-shadow: 0px 1px 6px #159AFF;
display: flex;
>div {
height: 33px;
overflow: hidden;
display: flex;
>div {
display: flex;
flex-direction: column-reverse;
animation: numIncrease 1s linear 1.3s;
animation-fill-mode: forwards;
transform: translateY(-100%);
>div {
height: 33px;
text-align: right;
}
}
}
}
@keyframes numIncrease {
0% {
transform: translateY(-100%);
}
100% {
transform: translateY(0%);
}
}边栏推荐
- 3--新唐nuc980 kernel支持jffs2, Jffs2文件系统制作, 内核挂载jffs2, uboot网口设置,uboot支持tftp
- Processing image files uploaded by streamlit Library
- Jacob Steinhardt, assistant professor of UC Berkeley, predicts AI benchmark performance: AI has made faster progress in fields such as mathematics than expected, but the progress of robustness benchma
- leetcode:736. LISP syntax parsing [flowery + stack + status enumaotu + slots]
- B站6月榜单丨飞瓜数据UP主成长排行榜(哔哩哔哩平台)发布!
- 如何设计好接口测试用例?教你几个小技巧,轻松稿定
- How to build a 32core raspberry pie cluster from 0 to 1
- Zhang Ping'an: accelerate cloud digital innovation and jointly build an industrial smart ecosystem
- [paper reading | deep reading] rolne: improving the quality of network embedding with structural role proximity
- Lidar: introduction and usage of ouster OS
猜你喜欢

人脸识别应用解析

String or binary data will be truncated

如何从0到1构建32Core树莓派集群

Linear list --- circular linked list

6-6漏洞利用-SSH安全防御

Increase 900w+ playback in 1 month! Summarize 2 new trends of top flow qiafan in station B

Tiflash source code reading (IV) design and implementation analysis of tiflash DDL module

Several classes and functions that must be clarified when using Ceres to slam

本周 火火火火 的开源项目!

Apifox,你的API接口文档卷成这样了吗?
随机推荐
Increase 900w+ playback in 1 month! Summarize 2 new trends of top flow qiafan in station B
The empirical asset pricing package (EAP) can be installed through pypi
老板被隔离了
阿里云易立:云原生如何破解企业降本提效难题?
GEE升级,可以实现一件run tasks
[C # notes] reading and writing of the contents of text files
How to build a 32core raspberry pie cluster from 0 to 1
Data connection mode in low code platform (Part 1)
This week's hot open source project!
C # / vb. Net supprime le filigrane d'un document word
STM32项目 -- 选题分享(部分)
String or binary data will be truncated
MySQL
postgresql之整体查询大致过程
[paper reading | deep reading] rolne: improving the quality of network embedding with structural role proximity
Pgadmin4 of PostgreSQL graphical interface tool
【Node学习笔记】chokidar模块实现文件监听
Tips for web development: skillfully use ThreadLocal to avoid layer by layer value transmission
安全交付工程师
[Mori city] random talk on GIS data (II)