views:

484

answers:

2

I am using AJAX modal popup in my project, 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?

+1  A: 

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 :)

Si Philp
Thanks, could you place some sample code?
Muhammad Akhtar
I have set this Css to other div z-index: 1001; position: relative; top: 0%; left: 0%; background-color: Transparent; filter: alpha(opacity=40);
Muhammad Akhtar
Is you code available online or can you post more?
Si Philp
Thank you Philp.
Muhammad Akhtar
A: 

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".

mahemoff