javascript - 我正在尝试通过显示进度条定期更改图像?
问题描述
我正在尝试定期更改图像。首先它显示一些正在运行的进度条,当进度条完成时,图像将被更改并且它会一次又一次地继续。我通过 css 动画和 javascript 实现这一点。我的问题如果我控制台.log() 如果我删除 console.log() 动画只播放一次,动画就可以工作。
let circle = $('.round');
let avatars = $('.avatars');
let i = 1;
let imageArray = [
'https://i.stack.imgur.com/Pyxho.jpg',
'https://i.stack.imgur.com/Pyxho.jpg',
'https://i.stack.imgur.com/Pyxho.jpg'
];
circle.on('animationend',function(){
$(this).css('animation','none');
console.log($(this).css('animation'));
avatars.attr('src',imageArray[i]);
$(this).css('animation','fill 5s linear 2s');
console.log($(this).css('animation'));
if(i < imageArray.length){
i++;
}else{
i=0;
}
});
#home .container svg{
position: absolute;
left: 50%;
transform: translateX(-50%);
}
#home .container svg .round{
stroke-dasharray: 534;
stroke-dashoffset: 534;
animation: fill 5s linear 2s;
}
#home .container .img{
width: 170px;
height:170px;
margin: 0 auto;
}
#home .container img{
display: block;
width: 100%;
height: 100%;
border-radius: 50%;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<section id="home">
<div class="container">
<svg width='172' height='172'>
<circle class='round' r='85' cx='86' cy='86' stroke-width='2' stroke='white' fill='none' />
</svg>
<div class="img">
<img class='avatars' src="https://i.stack.imgur.com/Pyxho.jpg" alt="Logo">
</div>
<h1>Bla Bla</h1>
<span id='typed'></span>
</div>
</section>
解决方案
推荐阅读
- bash - telnet 到来自多个来源的多个目标 IP 和端口
- mysql - 选择查询 3 个连接表
- rest - 如何传递参数以将数据发布到 REST API?
- unity3d - Unity - HDRI Skybox 用作眼睛适应/色调映射的光源
- regex - 正则表达式获取两组字符串?
- c# - 来自 Linux 的 .Net Core Microsoft.Web.Administration ServerManager
- php - 如何在 PHP 和 CodeIgniter 中的页眉和页脚之间显示 html 文件
- xamarin.ios - 如何将 iOS C++ 项目引用到 iOS C# 应用程序中
- scrapy - 在scrapy FormRequest上循环,但只创建了一项
- javascript - jquery中的数据表不显示打印按钮