Admin

May 24th

98 Comments

Share

Here will try to create a modal window using css and jquery. Two years ago light box came into our life and it changes the traditional look of modal windows. We all have used modal window plugins once in our life as web designer or developer but the problem with it is you have to use the same layout formation which comes with modal window plugin you can just style the layout of model window but today here we will learn how to create a custom modal window, means here we will pop up the whole custom styled DIV as model window. Check out the tutorial to learn it but before getting started check out demo first.

Check Out Demo First

Files Needed Before Starting

Jquery Library

Step 1 : XHTML

First of all we need to add <a> tag with attribute rel(set rel for popup window), class popup (to trigger the popupbox). Here we will use 3 <a> tags for 3 different types of custom popup window.

Then we will write a markup for popup which can be placed anywhere in the page. Important point is that the id of markup will be matched with rel attribute of <a> tag.

Check out the codes below

<h1><a href="#" rel="popuprel" class="popup">Click Here for 1st Custom Modal Window</a></h1>
<h1><a href="#" rel="popuprel2" class="popup">Click Here for 2nd Custom Modal Window</a></h1>
<h1><a href="#" rel="popuprel3" class="popup">Click Here for 3rd Custom Modal Window</a></h1>
 
<div class="popupbox" id="popuprel">
<!-- Content For Pop Up Box one -->
</div>
 
<div class="popupbox1" id="popuprel2">
<!-- Content For Pop Up Box Two -->
</div>
 
<div class="popupbox2" id="popuprel3">
<!-- Content For Pop Up Box Three -->
</div>

Step 2 : CSS

Here first off all we need to design 3 custom backgrounds for our pop up then will style it.


Now lets style popup markup.

/* Style you custom popupbox according to your requirement */
.popupbox {
	width:500px;
	height:300px;
	background-image:url(images/pop-up_03.png);
	background-repeat:no-repeat;
	display: none; /* Hidden as default */
	float: left;
	position: fixed;
	top: 50%; left: 50%;
	z-index: 99999;
	-webkit-box-shadow: 0px 0px 20px #000;
	-moz-box-shadow: 0px 0px 20px #000;
	box-shadow: 0px 0px 20px #000;
}
.popupbox2 {
	width:454px;
	height:307px;
	background-image:url(images/pu_03.png);
	background-repeat:no-repeat;
	display: none; 
	float: left;
	position: fixed;
	top: 50%; left: 50%;
	z-index: 99999;
	-webkit-box-shadow: 0px 0px 20px #000;
	-moz-box-shadow: 0px 0px 20px #000;
	box-shadow: 0px 0px 20px #000;
}
.popupbox3 {
	width:502px;
	height:302px;
	background-image:url(images/3_03.png);
	background-repeat:no-repeat;
	display: none;
	float: left;
	position: fixed;
	top: 50%; left: 50%;
	z-index: 99999;
	-webkit-box-shadow: 0px 0px 20px #000;
	-moz-box-shadow: 0px 0px 20px #000;
	box-shadow: 0px 0px 20px #000;
}
#fade { 
	display: none; /* Hidden as default */
	background: #000;
	position: fixed; left: 0; top: 0;
	width: 100%; height: 100%;
	opacity: .80;
	z-index: 9999;
}

Step 3 : Jquery

First step is to call jquery file which you download in local computer or you can link jquery file directly from Google code.

<script type="text/javascript" src="jquery-1.2.6.min.js"></script>

Now everything is set you got your jquery library linked with you document now lets create one more js file named custom.js and link it with you document and start writing codes in it.

<script type="text/javascript" src="jquery-1.2.6.min.js"></script>
<script type="text/javascript" src="custom.js"></script>
$(document).ready(function() {
	// Codes Goes Here...
});

Now lets get it working.. Check out below codes with full explanation in it. Thank You

$(document).ready(function() {
 
// Here we will write a function when link click under class popup				   
$('a.popup').click(function() {
 
 
// Here we will describe a variable popupid which gets the
// rel attribute from the clicked link							
var popupid = $(this).attr('rel');
 
 
// Now we need to popup the marked which belongs to the rel attribute
// Suppose the rel attribute of click link is popuprel then here in below code
// #popuprel will fadein
$('#' + popupid).fadeIn();
 
 
// append div with id fade into the bottom of body tag
// and we allready styled it in our step 2 : CSS
$('body').append('<div id="fade"></div>');
$('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn();
 
 
// Now here we need to have our popup box in center of 
// webpage when its fadein. so we add 10px to height and width 
var popuptopmargin = ($('#' + popupid).height() + 10) / 2;
var popupleftmargin = ($('#' + popupid).width() + 10) / 2;
 
 
// Then using .css function style our popup box for center allignment
$('#' + popupid).css({
'margin-top' : -popuptopmargin,
'margin-left' : -popupleftmargin
});
});

Demo Download

Note : You can add close button into it too. Play with the custom popup.

Want to pass ecommerce hosting exams? Check out our latest 352-001 study guides and 642-415 demos give you 100% exam pass guarantee of pass4sure 70-236. You can also get ccda certification dumps from this website.

Author : Admin

98 Responses to “Create Custom PopUp (Modal Window) with jQuery”

  1. TYRONE says:

    Zyprexa

    Buyno prescription…

  2. MARION says:

    Purim

    Buyno prescription…

  3. DONNIE says:

    prozac breast feeding

    Buydrugs without prescription…

  4. ALFREDO says:

    Reglan…

    Buywithout prescription…

  5. ADRIAN says:

    Pyridium@Pyridium.Pyridium” rel=”nofollow”>…

    Buygeneric meds…

  6. TERRANCE says:

    Pyrantel@Pamoate.now” rel=”nofollow”>..

    Buygeneric pills…

  7. JIMMIE says:

    Prozac@Prozac.Prozac” rel=”nofollow”>…

    Buynow…

  8. EARL says:

    Pulmicort@Pulmicort.Pulmicort” rel=”nofollow”>..

    Buyit now…

  9. JIMMY says:

    Prozac@Prozac.Prozac” rel=”nofollow”>…

    Buygeneric drugs…

  10. WILLIE says:

    Strattera@Strattera.Strattera” rel=”nofollow”>…

    Buynow it…

  11. BENJAMIN says:

    Prozac@Prozac.Prozac” rel=”nofollow”>.

    Buywithout prescription…

  12. DARREN says:

    Prozac@Prozac.Prozac” rel=”nofollow”>.

    Buygeneric drugs…

  13. LUKE says:

    Cialis@Cialis.Cialis” rel=”nofollow”>..

    Buyno prescription…

  14. STUART says:

    pediatric@griseofulvin.liver.tumors” rel=”nofollow”>…

    Buygeneric pills…

  15. OLIVER says:

    coral@calcium.ultra” rel=”nofollow”>…

    Buygeneric drugs…

  16. JAIME says:

    buy@human.growth.hormone.product” rel=”nofollow”>…

    Buygeneric drugs…

  17. IVAN says:

    do@you.need.to.fast.for.prograf.levels” rel=”nofollow”>…

    Buywithout prescription…

  18. GLEN says:

    .

    Buydrugs without prescription…

  19. DUSTIN says:

    early@childhood.purim.crafts” rel=”nofollow”>.

    Buygeneric drugs…

  20. ANTONIO says:

    purpose@of.advair” rel=”nofollow”>.

    Buygeneric meds…

  21. WILLARD says:

    if@you.are.allergic.to.ceclor.can.you.take.augmentin” rel=”nofollow”>…

    Buywithout prescription…

  22. EDDIE says:

    how@long.does.abilify.stay.in.your.system” rel=”nofollow”>…

    Buywithout prescription…

  23. JULIAN says:

    bulk@coral.calcium.powder” rel=”nofollow”>..

    Buygeneric drugs…

  24. JORDAN says:

    .

    Buywithout prescription…

  25. STEVE says:

    accupril@side.affects” rel=”nofollow”>…

    Buyno prescription…

  26. EDDIE says:

    does@clonidine.and.lamisil.interaction” rel=”nofollow”>..

    Buywithout prescription…

  27. BERNARD says:

    sexual@side.effects.of.lexapro.vs.paxil” rel=”nofollow”>..

    Buynow it…

  28. CLAUDE says:

    aciphex@vs.nexium” rel=”nofollow”>..

    Buygeneric drugs…

  29. SHANE says:

    dosage@of.albenza.for.human.hookworm.infection” rel=”nofollow”>…

    Buygeneric pills…

  30. JULIAN says:

    can@you.take.vicodin.with.prednisolone” rel=”nofollow”>.

    Buynow…

  31. FRANKLIN says:

    effexor@drug.interaction” rel=”nofollow”>.

    Buygeneric pills…

  32. LEE says:

    is@prometrium.and.blood.clots” rel=”nofollow”>..

    Buywithout prescription…

  33. SHAUN says:

    cutting@proscar.tablets” rel=”nofollow”>.

    Buygeneric pills…

  34. WARREN says:

    pulmicort@or.xopenex.first.when.using.both” rel=”nofollow”>…

    Buyit now…

  35. CASEY says:

    buy@online.amoxicillin” rel=”nofollow”>.

    Buywithout prescription…

  36. FRED says:

    neurontin@dyskinesia.tardive.dystonia” rel=”nofollow”>.

    Buygeneric drugs…

  37. WESLEY says:

    how@well.does.nexium.cure.barretts.esophagus” rel=”nofollow”>.

    Buygeneric drugs…

  38. NORMAN says:

    changing@from.paxil.to.paxil.cr” rel=”nofollow”>.

    Buyno prescription…

  39. JORDAN says:

    plan@b.skateboards.at.target” rel=”nofollow”>.

    Buywithout prescription…

  40. ALFRED says:

    where@to.buy.acai.berry.zen” rel=”nofollow”>…

    Buyno prescription…

  41. CARLTON says:

    flomax@in.dogs” rel=”nofollow”>.

    Buyit now…

  42. TED says:

    side@effectsof.flovent” rel=”nofollow”>..

    Buywithout prescription…

  43. JIMMY says:

    wholesale@ginseng.root” rel=”nofollow”>…

    Buyno prescription…

  44. TED says:

    ..

    Buynow it…

  45. ctilde says:

    Great One…

    I must say, its worth it! My link, http://donna.scoom.com/,thanks haha…

Leave a Reply