其他分享
首页 > 其他分享> > 如何使用纯js实现一个带有灰色半透明背景的弹出框

如何使用纯js实现一个带有灰色半透明背景的弹出框

作者:互联网

 

原文 如何使用纯js实现一个带有灰色半透明背景的弹出框

// 加入透明背景 
var body = document.body;
var backgroundDiv = document.createElement("div");
backgroundDiv.style.cssText = "left:0;top:0;
position:fixed;
background:#ddd;opacity:0.8;width:100%;height:100%";
body.appendChild(backgroundDiv);
// 加入居中弹出框
var newDiv = document.createElement("div");
newDiv.style.cssText = "position:absolute;margin:auto;
left:0;right:0;top:0;
bottom:0;width:400px;
height:200px;background:white;";
backgroundDiv.appendChild(newDiv); // 丰富弹出框内容 ......

 

标签:body,出框,js,backgroundDiv,newDiv,var,document,半透明
来源: https://www.cnblogs.com/xiaoshen666/p/10951323.html