简体   繁体   English

如何在不使用jQuery的情况下为javascript页面赋予淡出效果

[英]how to give fadeout effect to a page in javascript without using jQuery

.. i tried using the code in which the loading will keep on increasing till 100 until a new page will open.. ..我尝试使用其中加载将一直增加到100直到新页面打开的代码。

if(loading==90){
  preload.style.animation = "fadeOut 2s ease";
} 

but its not working 但它不起作用

使用css不透明度,1完全可见,0隐藏,0.5一半可见。

document.getElementById("yourId").style.opacity = "0.5";

You can append class to preload element 您可以将类追加到preload元素

 if (window.addEventListener) { window.addEventListener('load', cool, false); } function cool() { var preload = document.getElementById("preload"); var loading = 0; var id = setInterval(frame,64); function frame() { if(loading == 100) { clearInterval(id); // window.open("test1.html","_self"); } if(++loading == 90){ preload.className = "ld"; } } }; 
 #preload { position: absolute; display: block; left: 0; top: 0; background: tomato; width: 100%; height: 200px; transition: all 2s ease; } .ld { opacity: 0; } 
 <div id="preload"></div> test string 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM