lxw
2020-07-11 9db52f2f2dd3665fe9da1ae5657e0167c3a34d40
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// 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();    // 隐藏弹出框和遮罩层
});