简体   繁体   English

使用Javascript和CSS的模式弹出窗口

[英]Modal popup using Javascript and Css

I am using AJAX modal popup in my project, but there is problem with it. 我在项目中使用AJAX模态弹出窗口,但是存在问题。

Now I decided to acheive similar behaviour using javascript 现在,我决定使用javascript来实现类似行为

I am able to show popup using 我可以使用显示弹出窗口

document.getElementById('dv').style.display = "block";

Now I just need, how can I make background disable like in modal popup? 现在我只需要如何使背景禁用(如模式弹出窗口一样)?

you create a div that spans the whole page but initial style is display:none; 您创建了一个跨越整个页面的div,但初始样式为display:none;。 along with any other styles. 以及其他任何样式。 ie transparency 80% with background colour of black.. 即透明度为80%,背景色为黑色。

When you show dv change the display attribute of the div (above). 当显示dv时,请更改div的显示属性(如上)。 Just make sure that the dv has a higher z-index than the background div and the background div has a higher z-index than the content on the page :) 只要确保dv的z-index高于背景div,背景div的z-index高于页面上的内容即可:)

Have you considered using a library for this? 您是否考虑过为此使用图书馆? The most programmer-friendly and flexible I have found is NyroModal (jQuery based). 我发现对程序员最友好且最灵活的是NyroModal (基于jQuery)。 The advantage of a library is it will deal with many subtle things that happen with modal dialogs, eg ensuring it works effectively across all browsers (and overcomes the various quirks around things like positioning), animating on and off, lightbox effect around it. 库的优点是它将处理模态对话框中发生的许多细微问题,例如,确保它在所有浏览器中都能有效工作(并克服了诸如定位之类的各种怪癖),启用和禁用动画以及围绕它的灯箱效果。

NyroModal lets you generate dialogs dynamically, whereas most libraries are geared owards simpler use cases such as "make all images clickable so they show up as lightboxed when the user clicks on them". NyroModal允许您动态生成对话框,而大多数库都适合使用更简单的用例,例如“使所有图像都可单击,以便用户单击它们时将它们显示为灯箱”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM