A simple modal popup div or dialog can be done using CSS properties and a bit of jQuery. The basic idea is simple:
1. Create a div with a translucent background and show it on top of your content page by click. 2. Show your pop-up div or warning div on top of the translucent dimming / hiding div.
So we need three divs:
content (the main content of the site). hider (To reduce the content). popup_box (modal div to display).
First, let's define CSS:
#hider { position:absolute; top: 0%; left: 0%; width:1600px; height:2000px; margin-top: -800px; margin-left: -500px; z-index: 99; background-color:Black;
It is important that we set our zider index hider index lower than pop_up, since we want to show popup_box on top.
Here comes the java Script:
$(document).ready(function () { //hide hider and popup_box $("#hider").hide(); $("#popup_box").hide(); //on click show the hider div and the message $("#showpopup").click(function () { $("#hider").fadeIn("slow"); $('#popup_box').fadeIn("slow"); }); //on click hide the message and the $("#buttonClose").click(function () { $("#hider").fadeOut("slow"); $('#popup_box').fadeOut("slow"); }); });
And finally, HTML:
<div id="hider"></div> <div id="popup_box"> Message<br /> <a id="buttonClose">Close</a> </div> <div id="content"> Page main content.<br /> <a id="showpopup">ClickMe</a> </div>
I used jquery-1.4.1.min.js www.jquery.com/download and tested the code in Firefox. Hope this helps.
source share