开发者

Modal popup using Javascript and Css

I am using AJAX modal popup in my pr开发者_开发百科oject, but there is problem with it.

Now I decided to acheive similar behaviour using 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; along with any other styles. i.e transparency 80% with background colour of black..

When you show dv change the display attribute of the div (above). 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 :)


Have you considered using a library for this? The most programmer-friendly and flexible I have found is NyroModal (jQuery based). The advantage of a library is it will deal with many subtle things that happen with modal dialogs, e.g. 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".

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜