打开弹出窗口时禁用后台所有内容
问题描述:
我通过单击一个按钮(#but1)打开一个弹出窗口,并通过应用以下jquery使用按钮(#but2)将其关闭-
I open a pop-up by clicking on a button(#but1) and close it using button(#but2) by applying following jquery-
$(document).ready(function(){
$("#but1").click(function(){
$("#popdiv").fadeTo(200,1);
});
$("#but2").click(function(){
$("#popdiv").fadeOut(200);
});
});
弹出窗口的CSS是-
#popdiv
{
height:300px;
width:420px;
background-color:#97ceaa;
position:fixed;
top:200px;
left:250px;
display:none;
}
我想在弹出窗口出现后禁用背景.弹出窗口出现后,应禁用鼠标悬停效果,并且我不应该在背景上单击任何东西.我怎样才能做到这一点?是否可以仅使用CSS来做到这一点?
I want to disable the background after my pop-up appears. After my pop-up appears the mouse-hover effects should be disabled, and I should not be able to click anything at the back-ground. How can I achieve this? Is it possible to do this using only CSS?
答
只需将其放在另一个填充页面(并显示该页面)的容器中:
Just put it inside another container that fills the page (and show that):
$(function() {
$("#but1").click(function() {
$(".fullscreen-container").fadeTo(200, 1);
});
$("#but2").click(function() {
$(".fullscreen-container").fadeOut(200);
});
});
.fullscreen-container {
display: none;
position: fixed;
top: 0;
bottom: 0;
left: 0;
right: 0;
background: rgba(90, 90, 90, 0.5);
z-index: 9999;
}
#popdiv {
height: 300px;
width: 420px;
background-color: #97ceaa;
position: fixed;
top: 50px;
left: 50px;
}
body {
padding-top: 65px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button id="but1">Open dialog</button>
<div class="fullscreen-container">
<div id="popdiv">
<h1>
Dialog content!
</h1>
<button id="but2">Close dialog</button>
</div>
</div>