javascript - close button for jquery popup box -
i using code popup box , it's work well
$(document).ready(function() { // here write function when link click under class popup $('a.popup').click(function() { // here describe variable popupid gets // rel attribute clicked link var popupid = $(this).attr('rel'); // need popup marked belongs rel attribute // suppose rel attribute of click link popuprel here in below code // #popuprel fadein $('#' + popupid).fadein(); // append div id fade bottom of body tag // , allready styled in our step 2 : css $('body').append('<div id="fade"></div>'); $('#fade').css({'filter' : 'alpha(opacity=80)'}).fadein(); // here need have our popup box in center of // webpage when fadein. add 10px height , width var popuptopmargin = ($('#' + popupid).height() + 10) / 2; var popupleftmargin = ($('#' + popupid).width() + 10) / 2; // using .css function style our popup box center allignment $('#' + popupid).css({ 'margin-top' : -popuptopmargin, 'margin-left' : -popupleftmargin }); }); // define 1 more function used fadeout // fade layer , popup window click on fade layer $('#fade').click(function() { // add markup ids of custom popup box here $('#fade , #popuprel , #popuprel2 , #popuprel3').fadeout() return false; }); });
and it's html code:
<div class="popupbox" id="popuprel"> <div id="intabdiv"> <h2>content demo 1</h2> <p>check out webdesignersdesk more tutorials</p> </div> </div> <div id="fade"></div>
but popup box close when click outside popup box want add close button in box , when click close box. how can it?
try this..
html:
<div class="popupbox" id="popuprel"> <div id="intabdiv"> <h2>content demo 1</h2> <p>check out webdesignersdesk more tutorials</p> </div> <div class="closepopup">close</div> </div> <div id="fade" class="fade"></div>
javascript:
$('.closepopup').on('click', function(e) { $('.popupbox').fadeout(); $('.fade').fadeout(); });
Comments
Post a Comment