[英]Change background colour and transparency when adding a “modal div”
I am having a page that at some point shows a hidden div and adds a form for inputing some data. 我有一个页面,该页面有时显示一个隐藏的div,并添加了用于输入一些数据的表单。 You can call it a modal div perhaps. 您可以将其称为模式div。
What I want to do is to grey out everything else and only allow interaction with the mentioned div. 我想做的是将其他所有内容都显示为灰色,只允许与上述div进行交互。 I want the background to be grey and transparent. 我希望背景是灰色和透明的。
What is the best strategy for this? 最好的策略是什么? Adding a image and stretching it in some way and making it transparent? 添加图像并以某种方式拉伸并使其透明? Is it possible to make that image catch all events that ends up outside my form-div? 是否有可能使该图像捕捉到所有在我的form-div之外发生的事件? How to do this? 这个怎么做?
Any other, better way? 还有其他更好的方法吗?
I am using jquery so best way is if I can se any jquery api for this. 我正在使用jquery,所以最好的方法是是否可以为此使用任何jquery api。
This is actually not that complicated. 这实际上并不那么复杂。 It can be done in a line or two: 可以在一两行中完成:
/* initialize it */
$(document.body).append("<div id='shadow' style='position:fixed;left:0px;top:0px;width:100%; height:100%; background:black;'></div>").find("#shadow").hide();
/* show it */
$("#shadow").fadeTo(200,0.5);
/* hide it */
$("#shadow").fadeTo(200,0);
then just make sure to set the form to a z-index higher than the shadow. 然后只需确保将表单的z-index设置为高于阴影。
You can do this by using a Modal jQuery Dialog . 您可以使用Modal jQuery Dialog来做到这一点。 It will grey out the background and disable editing on the page except for the dialog. 它将使背景变灰,并禁用对话框以外的页面上的编辑。
Make a div overlap the whole page. 使div覆盖整个页面。 That div is 50% transparent and grey. 该div为50%透明和灰色。 Then your modal div comes on top of that. 然后,您的模式div便是最重要的。
More info: Snippets: Howto Grey-Out The Screen 更多信息: 片段:如何将屏幕显示为灰色
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.