javascript - how to close an overlay by clicking the page -
i've javascript file :
var $overlay_wrapper; var $overlay_panel; function show_overlay() { if ( !$overlay_wrapper ) append_overlay(); $overlay_wrapper.fadein(700); $overlay_panel.fadein(700); } function hide_overlay() { $overlay_wrapper.fadeout(500); $overlay_panel.fadeout(500); } function append_overlay() { $overlay_wrapper = $('<div id="overlay"></div>').appendto( $('body') ); $overlay_panel = $('<div id="overlay-panel"></div>').appendto( $('body') ); $overlay_panel.html( '<p>this overlay content</p><a href="#" class="hide-overlay">x close</a>' ); attach_overlay_events(); } function attach_overlay_events() { $('a.hide-overlay', $overlay_panel).click( function(ev) { ev.preventdefault(); hide_overlay(); }); } $(function() { $('a.show-overlay').click( function(ev) { ev.preventdefault(); show_overlay(); }); });
but overlay closed if click "x close" link . want overlay closed if click in page that's transparant(outside content). how can that? please , suggest. thank you.
when append overlay body, attach click event listener:
$('#overlay').click(function(){ $('.hide-overlay').trigger('click'); });
when div clicked trigger "x close" click handler;
Comments
Post a Comment