function isExist(elem){ if(typeof elem !== 'undefined' && typeof elem !== null) { return true; }else{ return false; } } var addCover = function(){ removeCover(); var coverCss = { position: 'fixed', zIndex: '100', top : '0px', left: '0px', bottom: '0px', right: '0px', backgroundColor:'#000', opacity: 0.6 } var cover = $('
'); $('body').append(cover.css(coverCss)); } var removeCover = function(){ if(isExist($('#cover'))) $('#cover').remove(); } function popup(target){ addCover(); target.css('position','fixed') .css("top",($(window).height()-target.height())/2) .css("left",($(window).width()-target.width())/2) .css("z-index","9999") .fadeIn(); $(".close").on('click',function(){ removeCover(); target.fadeOut(); return false; }); } $('a').on('click',function(){ popup($('.popup')) })