我是编程新手,想用JS和HTML制作点击游戏。现在我想添加成就。它们应该弹出,并显示几秒钟(5可能?)秒,然后逐渐消失。
到目前为止,我有一个解决方案,但该功能将每10秒运行一次。如果你应该在6日之后获得成就。第二,弹出窗口将显示2到4秒,然后逐渐消失。
简单地说,当完成成就时,成就(div)应弹出,在那里停留5秒钟,然后逐渐消失。
这是我的JS:
//Check if achievement #1 is completed / true:
if(Ach1up == true){
Modal1stAch.style.display = "block";
Ach1up = null;
}
//Fade-out function
setTimeout(function () {
Modal1stAch.style.opacity = "0.0";
Modal1stAch.style.WebkitTransition = "2s";
Modal1stAch.style.transition = "2s";
}, 10000);
答案 0 :(得分:0)
如果我理解正确,你需要的是将你的fadeout代码抓到一个函数中,并在ach1up为真后5s调用它。
//Check if achievement #1 is completed / true:
if(Ach1up == true){
Modal1stAch.style.display = "block";
Ach1up = null;
setTimeout(function () { //wait 5 seconds to fade the popup
popupFadeOut();
}, 5000);
}
//Fade-out function
// you write it, and wait to be called.
function popupFadeOut() {
Modal1stAch.style.opacity = "0.0";
Modal1stAch.style.WebkitTransition = "2s";
Modal1stAch.style.transition = "2s";
}