码迷,mamicode.com
首页 > Web开发 > 详细

js body添加元素 带样式

时间:2020-07-29 12:39:59      阅读:206      评论:0      收藏:0      [点我收藏+]

标签:mat   nim   type   添加   pac   win   http   div   onload   

function 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();
}

感谢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.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!