当前位置:网站首页>数字滚动增加效果
数字滚动增加效果
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%);
}
}边栏推荐
- MySQL
- Real project, realized by wechat applet opening code (end)
- unity中跟随鼠标浮动的面板,并可以自适应文字内容的大小
- [paper reading | deep reading] dngr:deep neural networks for learning graph representations
- Web3对法律的需求
- The cities research center of New York University recruits master of science and postdoctoral students
- Tiflash source code reading (IV) design and implementation analysis of tiflash DDL module
- 所谓的消费互联网仅仅只是做行业信息的撮合和对接,并不改变产业本身
- Station B's June ranking list - feigua data up main growth ranking list (BiliBili platform) is released!
- 1个月增长900w+播放!总结B站顶流恰饭的2个新趋势
猜你喜欢

建議收藏!!Flutter狀態管理插件哪家强?請看島上碼農的排行榜!

String or binary data will be truncated

FLIR blackfly s usb3 industrial camera: how to use counters and timers

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

老板被隔离了
![[paper reading | deep reading] anrl: attributed network representation learning via deep neural networks](/img/06/17acf9958228cce5d80ada3275ad24.png)
[paper reading | deep reading] anrl: attributed network representation learning via deep neural networks
![leetcode:736. LISP syntax parsing [flowery + stack + status enumaotu + slots]](/img/0d/e07fe970167368040eb09b05c3682e.png)
leetcode:736. LISP syntax parsing [flowery + stack + status enumaotu + slots]

Stm32f4 --- PWM output

postgresql之整体查询大致过程

Application analysis of face recognition
随机推荐
Linear list --- circular linked list
Station B's June ranking list - feigua data up main growth ranking list (BiliBili platform) is released!
低代码平台中的数据连接方式(上)
企业中台建设新路径——低代码平台
老板被隔离了
企业中台建设新路径——低代码平台
STM32项目 -- 选题分享(部分)
Rethinking of investment
【软件测试】最全面试问题和回答,全文背熟不拿下offer算我输
1 -- Xintang nuc980 nuc980 porting uboot, starting from external mx25l
进程管理基础
Difference and the difference between array and array structure and linked list
The cities research center of New York University recruits master of science and postdoctoral students
Data connection mode in low code platform (Part 1)
A new path for enterprise mid Platform Construction -- low code platform
Halcon实例转OpenCvSharp(C# OpenCV)实现--瓶口缺陷检测(附源码)
Recommended collection!! Which is the best flutter status management plug-in? Please look at the ranking list of yard farmers on the island!
go swagger使用
B站6月榜单丨飞瓜数据UP主成长排行榜(哔哩哔哩平台)发布!
PostgreSQL图形化界面工具之pgAdmin4