gpt4 book ai didi

javascript - 加载带有淡出效果的页面

转载 作者:行者123 更新时间:2023-12-03 02:11:21 25 4
gpt4 key购买 nike

我想在超时后插入淡出效果。
我阅读了如何插入淡出,但无法将其插入到我的代码中。

(function() {
if (window.addEventListener) {
window.addEventListener("load", nascondi_loading_screen, false);
} else {
window.attachEvent("onload", nascondi_loading_screen);
}
})();

function mostra_loading_screen() {
document.getElementById("loading_screen").style.display = 'block';
}

function nascondi_loading_screen() {
setTimeout(function() {
document.getElementById("loading_screen").style.display = 'none';
}, 3000);
}

mostra_loading_screen();
#loading_screen {
z-index: 1000;
display: none;
position: absolute;
left: 0px;
top: 0px;
height: 100%;
width: 100%;
background-color: white;
color: white;
text-align: center;
padding-top: 100px;
opacity: 0.5;
opacity: 1;
filter: alpha(opacity=50);
}
<div id="loading_screen">
<img class="uk-position-center" src="images/loader.gif">
</div>

最佳答案

元素要么显示,要么不显示。你无法对此进行过渡。但是,您可以通过设置不透明度动画来淡出。为此,在 js 中设置不透明度:

 document.getElementById("loading_screen").style.opacity = 0 /* or 1 to fade in */;

然后在该属性上设置 css 转换:

 #loading_screen {
transition: opacity ease 2s;
}

关于javascript - 加载带有淡出效果的页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49558251/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com