jQuery Overlay 仅关注特定 div。请问没有插件吗?
我正在尝试使用 jQuery 实现模式叠加。
当用户单击特定按钮时,必须打开弹出 div。页面的其余部分应呈灰色。换句话说,除了这个弹出窗口之外,页面上的任何内容都不能被选择或单击。
如何才能实现这一目标?
我无法只关注 div。对我来说,背景也是活跃的。如何禁用弹出 div 以外的区域?
HTML:
<div id="mainContainer">
I am in the main body section.
</div>
<input type="button" value="Show Overlay" id="btn">
<div id="overlayContainer">
I am in the Overlay Section<span style="float:right"><a class="alink" href="javascript:void(0);">X</a></span>
</div>
JS:
$(function() {
$("#btn").click(function() {
$("#overlayContainer").fadeIn();
$("#mainContainer");
})
$(".alink").click(function() {
$(this).parent().parent().hide();
});
})
CSS:
#mainContainer{border:2px solid red;width:700px;height:500px;margin:0 auto;}
#overlayContainer{background:#c0c0c0;width:300px;height:400px;right:500px;border:2px dotted blue;margin-top:-460px;display:none;position:fixed;}
input{text-align:center;margin-left:300px;margin-top:18px;position:fixed;}
I am trying to achieve a modal overlay using jQuery.
When a user clicks on a particular button the popup div has to open up. The rest of the page should be grayed out. In other words nothing on the page can be selected or clicked other than this pop up.
How can this be acheived?
I have written the follwing: CODE and result is HERE
I am not able to focus only on the div. For me the background is also active. How do I disable the area other than the pop up div?
HTML:
<div id="mainContainer">
I am in the main body section.
</div>
<input type="button" value="Show Overlay" id="btn">
<div id="overlayContainer">
I am in the Overlay Section<span style="float:right"><a class="alink" href="javascript:void(0);">X</a></span>
</div>
JS:
$(function() {
$("#btn").click(function() {
$("#overlayContainer").fadeIn();
$("#mainContainer");
})
$(".alink").click(function() {
$(this).parent().parent().hide();
});
})
Css:
#mainContainer{border:2px solid red;width:700px;height:500px;margin:0 auto;}
#overlayContainer{background:#c0c0c0;width:300px;height:400px;right:500px;border:2px dotted blue;margin-top:-460px;display:none;position:fixed;}
input{text-align:center;margin-left:300px;margin-top:18px;position:fixed;}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您没有要求任何插件,但随后标记了您的问题 jquery-ui,它本身就是一个插件。首先,这是您的 jQuery-UI 答案:
http://jsfiddle.net/AMM2M/5/
并且这是您的无插件答案:
用覆盖 div 覆盖整个页面,然后在其上放置一个弹出 div。要显示弹出窗口,请显示和隐藏公共容器。
http://jsfiddle.net/AMM2M/6/
通过我的 Windows 7 手机回答< /sup>
You asked for no plugins, but then tagged your question jquery-ui, which is itself a plugin. First, here's your jQuery-UI answer:
http://jsfiddle.net/AMM2M/5/
And here's your no plugin answer:
Cover the entire page with an overlay div, then place a popup div over that. To display the popup, show and hide a common container.
http://jsfiddle.net/AMM2M/6/
Answered from my Windows 7 Phone
这是您的想法吗?
jquery 部分...
HTML
CSS
如果不让我知道我会尽力帮助你。如果您需要任何有关 jQuery 的解释,请告诉我。
Is this what you were thinking?
jquery part...
HTML
CSS
if it's not let me know I'll try to help you out. If you need any explanation in regards to the jQuery let me know.
Yuo 可以在覆盖层下方放置一个额外的灰色图层,其透明度为 50% 拉伸至 100% 大小。
Yuo can have an additional grey layer placed below your overlay with transparency at 50% stretched to 100% size.