js body添加元素 带样式
2021-01-15 07:15
标签:mat nim type 添加 pac win http div onload 感谢https://www.cnblogs.com/cynthia-wuqian/p/5363736.html js body添加元素 带样式 标签:mat nim type 添加 pac win http div onload 原文地址:https://www.cnblogs.com/zonglonglong/p/13396061.htmlfunction createStyle(){
return"*{padding:0;margin:0;border:0}.loading{width:640px;height:1024px;margin:0 auto}.loadImg{width:640px;height:1024px;animation:fadeInOut 3s linear;-webkit-animation:fadeInOut 3s linear;-moz-animation:fadeInOut 3s linear;opacity:0}@keyframes fadeInOut{0%{opacity:0}25%{opacity:.5}45%{opacity:1}50%{opacity:1}55%{opacity:1}75%{opacity:.5}100%{opacity:0}}@-moz-keyframes fadeInOut{0%{opacity:0}25%{opacity:.5}45%{opacity:1}50%{opacity:1}55%{opacity:1}75%{opacity:.5}100%{opacity:0}}@-webkit-keyframes fadeInOut{0%{opacity:0}25%{opacity:.5}45%{opacity:1}50%{opacity:1}55%{opacity:1}75%{opacity:.5}100%{opacity:0}}"
}
function addStyle(){
var style = document.createElement("style");
style.type = "text/css";
style.innerHTML = createStyle();
window.document.head.appendChild(style);
}
function addDom(){
var div = document.createElement("div");
div.className = "loading";
window.document.body.appendChild(div);
var img = document.createElement("img");
img.src="img/bg.png";
img.id="loadImg";
img.className="loadImg";
div.appendChild(img);
}
window.onload=function(){
addStyle();
addDom();
}
下一篇:C# Switch语句