[英]How would I apply a fade out animation to each of the icons in my menu within a for loop
im currently working on an animation where there's a delay between each of the icons when fading out.我目前正在研究 animation,其中每个图标之间在淡出时都有延迟。 The fade out animation works fine, but only on the first icon and im unsure on why this is.
淡出 animation 工作正常,但仅在第一个图标上,我不确定这是为什么。 Could some one maybe point out the mistake im making?
有人可以指出我犯的错误吗?
Javascript code: Javascript 代码:
function closeHorizontalWindow()
{
const delay = 150;
const reasons = ['btnReady', 'btnNotReady', 'btnBreak', 'btnEmail', 'btnLunch',
'btnComfortBreak', 'btnMeeting', 'btnChat']
for (let i = 0; i < reasons.length; i++) {
document.getElementById(reasons[i]).style.animation = `reasonsfadeout 0.45s ease-out
forwards ${delay}ms`
delay+=150
}
CSS code: CSS 代码:
@keyframes reasonsfadeout
{
from{opacity: 1; }
to {opacity: 0; }
}
} }
Thankyou谢谢
You can use an interval to iterate instead of a regular for-loop.您可以使用间隔来迭代而不是常规的 for 循环。
function closeHorizontalWindow()
{
const delay = 150;
const reasons = ['btnReady', 'btnNotReady', 'btnBreak', 'btnEmail', 'btnLunch',
'btnComfortBreak', 'btnMeeting', 'btnChat']
let i = 0;
const interval = setInterval(function(){
document.getElementById(reasons[i]).style.animation = `reasonsfadeout 0.45s ease-out forwards ${delay}ms`;
i++;
if(i>=reasons.length){
clearInterval(interval);
}
}, delay);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.