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
function fgPanel() {
    this.panel = $('.fg-panel');
    this.content = this.panel.find('.fg-panel-content');
    this.btn = this.panel.find('.fg-panel-btn');
}
 
fgPanel.prototype.show = function() {
    // 初始化面板高度
    var srn = $.mobile.getScreenHeight();    // 屏幕的高度
 
    // 生成面板左侧的遮罩层
    var mask = $('<div class="fg-panel-mask" onclick="panel.hide();"></div>');
    mask.css({
        'height': srn + 'px'
    });
    // 判断panel所在的页面是否展示
    if(this.panel.parent().hasClass('ui-page-active')) {
        $('div[data-role="page"]').append(mask);
 
        // 定义面板的高度并显示面板
        this.panel.height(srn - 16);
        this.content.height(srn - 96);
        this.panel.animate({'right': 0},500);
    }
    
}
fgPanel.prototype.hide = function(isTop) {
    if(isTop != undefined || isTop == true) {
        $(document).scrollTop(0);
    }    
    $('.fg-panel-mask').remove();
    this.panel.animate({'right': '-80%'},500);
}
var panel = new fgPanel();
 
// 当横屏和竖屏切换时更改面板的高度
$(window).on("orientationchange",function(){
    setTimeout(function() {
        var srnWidth = $(window).width();
        var posR = panel.panel.offset().left;
        if(srnWidth > posR) {
            panel.show();
        }
    }, 200);
});