// define class Popup
|
|
function Popup(param) {
|
this.popup = param;
|
this.height = this.popup.height();
|
}
|
|
Popup.prototype.showPopup = function() {
|
var winHt = $(window).height();
|
var popupMask = $('<div class="popup-mask"></div>');
|
$('body').append(popupMask);
|
$('.popup-mask').animate({height: winHt+"px"});
|
this.centerPopup();
|
this.popup.css('visibility', 'visible');
|
//console.info('显示执行成功!!!');
|
};
|
|
Popup.prototype.centerPopup = function() {
|
var winHt = $(window).height();
|
this.height = this.popup.height();
|
var marginTop = (winHt - this.height)/2;
|
this.popup.css('top', marginTop + 'px');
|
};
|
|
Popup.prototype.hidePopup = function() {
|
this.popup.css('top', -9999+'px');
|
$('.popup-mask').animate({height:0},function() {
|
|
$('.popup-mask').remove();
|
});
|
//console.info('隐藏执行成功!!!');
|
};
|
|
var popup = new Popup($('.popup').eq(0));
|
$('.popup').eq(0).find('.close').bind('click', function() {
|
popup.hidePopup(); // 隐藏弹出框和遮罩层
|
});
|
$('[data-toggle="popup"]').click(function() {
|
popup.showPopup(); // 显示弹出框和遮罩层
|
});
|
/*$('body').on('click', '.popup-mask', function() {
|
popup.hidePopup(); // 隐藏弹出框和遮罩层
|
});*/
|
// 窗口大小改变
|
$(window).resize(function() {
|
popup.hidePopup(); // 隐藏弹出框和遮罩层
|
});
|