功能介绍:点击一个按钮,然后页面会弹出一个窗口,而页面原来的内容会保持不变,只是在其页面上加了一个遮罩层,设置了不透明度,弹出的窗口可设置在固定位置,也可以自由设定,常见于网站的登录按钮。
html页面:
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"><title>js实现一个弹出框</title><style type="text/css">
/*预先写好弹出窗的样式*/
#menu{height: 900px;}
#close{
width:30px;
height:30px;
cursor:pointer;
position:absolute;
right:5px;
top:5px;
text-indent:-999em;
background-color:blue;
}
#mask{
background-color:pink;
opacity:0.5;
filter: alpha(opacity=50);
position:absolute;
left:0;
top:0;
z-index:1;
}
#login{
position:fixed;
z-index:2;
}
.loginCon{
position:relative;
width:670px;
height:380px;
/*background:url(img/loginBg.png) #2A2C2E center center no-repeat;*/
background-color: #ccc;
}
</style><div id="menu">
<div id="login-area">
<button id="btnLogin">登录</button>
</div>
</div>
<p>js代码:</p><div class="aritcle_card flexRow artxards">
<div class="artcardd flexRow">
<a class="aritcle_card_img" rel="nofollow" href="/xiazai/skill13718" title="使用 Husky 在 JavaScript 仓库中强制执行本地 Git 钩子检查"><img
src="https://img.php.cn/upload/skill/001/246/273/6adaf20dee630206.jpg" alt="使用 Husky 在 JavaScript 仓库中强制执行本地 Git 钩子检查" onerror="this.onerror='';this.src='/static/lhimages/moren/morentu.png'" ></a>
<div class="aritcle_card_info flexColumn">
<a rel="nofollow" href="/xiazai/skill13718" title="使用 Husky 在 JavaScript 仓库中强制执行本地 Git 钩子检查" class="overflowclass">使用 Husky 在 JavaScript 仓库中强制执行本地 Git 钩子检查</a>
<p class="overflowclass">使用 Husky 将 pre-commit、pre-push 和 commit-msg 检查集成到仓库中,以便代理和开发人员在更改离开工作站之前运行相同的本地防护措施。</p>
</div>
<a rel="nofollow" href="/xiazai/skill13718" title="使用 Husky 在 JavaScript 仓库中强制执行本地 Git 钩子检查" class="aritcle_card_btn flexRow flexcenter"><b></b><span>下载</span>
</a>
</div>
</div>
<div class="jb51code">
<pre class="brush:js;">
<script>
function openNew(){
//获取页面的高度和宽度
var sWidth=document.body.scrollWidth;
var sHeight=document.body.scrollHeight;
//获取页面的可视区域高度和宽度
var wHeight=document.documentElement.clientHeight;
var oMask=document.createElement("div");
oMask.id="mask";
oMask.style.height=sHeight+"px";
oMask.style.width=sWidth+"px";
document.body.appendChild(oMask);
var oLogin=document.createElement("div");
oLogin.id="login";
oLogin.innerHTML="<div class='loginCon'><div id='close'>关闭</script>
Java免费学习笔记:立即使用
解锁 Java 大师之旅:从入门到精通的终极指南










