JS:透明模态弹窗
作者:互联网
简单实现:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> </head> <body> <style> body { margin: 0; padding: 0; position: relative; } .btn { position: absolute; } .bk { height: 100%; width: 100%; position: fixed; background-color: rgba(100, 100, 100, 0.8); } .login { width: 400px; height: 300px; margin: 0 auto; margin-top: 10%; background-color: #fff; } </style> <button class="btn">点我</button> <script> //获取按钮 var btn = document.querySelector('.btn'); //点击按钮触发的事件 btn.onclick = function () { //获取body,创建一个蒙版层 var body = document.querySelector('body') var bk = document.createElement('div'); //添加一个类名 bk.classList.add('bk'); body.appendChild(bk); //创建一个登录的盒子 var login = document.createElement('div') bk.appendChild(login) login.classList.add('login'); } </script> </body> </html>
标签:模态,body,btn,bk,var,login,JS,document,弹窗 来源: https://www.cnblogs.com/LIXI-/p/16484781.html