当前位置:网站首页>数字滚动增加效果
数字滚动增加效果
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
- MetaForce原力元宇宙佛萨奇2.0智能合约系统开发(源码部署)
- 新一代云原生消息队列(一)
- 6-6漏洞利用-SSH安全防御
- Collection recommandée!! Quel plug - in de gestion d'état flutter est le plus fort? Regardez le classement des manons de l'île, s'il vous plaît!
- Rethinking of investment
- 【服务器数据恢复】raid损坏导致戴尔某型号服务器崩溃的数据恢复案例
- Recommended collection!! Which is the best flutter status management plug-in? Please look at the ranking list of yard farmers on the island!
- CSDN 夏令营课程 项目分析
- Lombok同时使⽤@Data和@Builder 的坑
猜你喜欢
Argo workflows source code analysis
Introduction to FLIR blackfly s industrial camera
[server data recovery] data recovery case of a Dell server crash caused by raid damage
3 -- Xintang nuc980 kernel supports JFFS2, JFFS2 file system production, kernel mount JFFS2, uboot network port settings, and uboot supports TFTP
Summer Challenge database Xueba notes (Part 2)~
leetcode:736. Lisp 语法解析【花里胡哨 + 栈 + 状态enumaotu + slots】
[paper reading | deep reading] graphsage:inductive representation learning on large graphs
阿里云易立:云原生如何破解企业降本提效难题?
Zhang Ping'an: accelerate cloud digital innovation and jointly build an industrial smart ecosystem
Big guys gather | nextarch foundation cloud development meetup is coming!
随机推荐
CSDN 夏令营课程 项目分析
长安链学习笔记-证书研究之证书模式
postgresql之integerset
真实项目,用微信小程序开门编码实现(完结)
Decryption function calculates "task state and lifecycle management" of asynchronous task capability
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
postgresql 之 数据目录内部结构 简介
unity中跟随鼠标浮动的面板,并可以自适应文字内容的大小
C语言练习题_1
[leetcode]Search for a Range
Station B's June ranking list - feigua data up main growth ranking list (BiliBili platform) is released!
Lidar: introduction and usage of ouster OS
postgresql之整体查询大致过程
1--新唐nuc980 NUC980移植 UBOOT,从外部mx25l启动
Metaforce force meta universe development and construction - fossage 2.0 system development
C#/VB. Net to delete watermarks in word documents
【Node学习笔记】chokidar模块实现文件监听
[Mori city] random talk on GIS data (II)
企业中台建设新路径——低代码平台
建議收藏!!Flutter狀態管理插件哪家强?請看島上碼農的排行榜!