简体   繁体   English

根据当前屏幕窗口大小为我的模式窗口设置max-height

[英]set max-height for my modal window based on the current screen window size

I have the following script which will show a modal window for my partial view:- 我有以下脚本,该脚本将为我的局部视图显示一个模式窗口:

$(function () {
        $.ajaxSetup({ cache: false });
        $("a[data-modal]").on("click", function (e) {        
            $('#myModalContent').load(this.href, function () {
                $('#myModal').modal({
                    keyboard: true
                }, 'show');

                bindForm(this);
            });
            return false;
        });


    });

and I set the following css:- 我设置以下css:

#myModalContent {
   max-height: 400px;
   overflow-y: auto;
}

but let say on a small size window the max-height of 400px will not be consistent if the actual screen size is less than this such as in a mobile screen. 但可以说,在小尺寸窗口中,如果实际屏幕尺寸小于400px,例如在移动屏幕中,则其最大高度将不一致。 so my question is how I can set the max-height for the modal window to be 80% of the current screen size ? 所以我的问题是如何将模式窗口的最大高度设置为当前屏幕尺寸的80%?

Thanks 谢谢

How about $("#myModalContent).css("max-height", screen.height * .80); 怎么样$("#myModalContent).css("max-height", screen.height * .80);

That might work 那可能有用

只需在样式表中使用%插入的px

For pure css solution. 对于纯CSS解决方案。

#modalname .modal-body {
    max-height: calc(100vh - 200px);
    overflow-y: auto;
}

here 100vh-> 100% of height. 在这里100vh->高度的100%。 200px is the approx combine space(height) used by modal header and footer. 200px是模态页眉和页脚使用的大约合并空间(高度)。

css solution is better than js as on window size change, it will directly adjust the height of the modal. css解决方案比js更好,因为在改变窗口大小时,它将直接调整模态的高度。

Use this: 用这个:

#myModalContent {
    height:400px;
    max-height:80%;
    overflow-y:auto;
}

Maybe you also need: 也许您还需要:

html, body {
    height:100%;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM