[英]How to make jQuery UI dialog occupy full window and dynamically adjust to window size change?
At the moment, I can set width
attribute to auto
to take the full width of the window, and it dynamically adjust itself if the window size is being changed (eg re-sizing the browser windows or displaying it on a different screen size).目前,我可以将
width
属性设置为auto
以获取窗口的整个宽度,如果窗口大小发生变化(例如,重新调整浏览器窗口的大小或在不同的屏幕大小上显示),它会动态调整自身。 Example: http://jsfiddle.net/NnsN2/示例: http : //jsfiddle.net/NnsN2/
However, I can't get the height
to work the same.但是,我无法获得相同的
height
。 It will always be the minimum height that will fit the content, even though I've tried setting it to auto
.它始终是适合内容的最小高度,即使我已尝试将其设置为
auto
。
The usual approach of getting the window height first ( $(window).height()
) and use that for height
doesn't work here, because it will be static and will not dynamically adapt to change of window size.首先获取窗口高度(
$(window).height()
)并将其用于height
的常用方法在这里不起作用,因为它将是静态的并且不会动态适应窗口大小的变化。
How can I make the height always take the full height of the window as well as be able to adapt itself to window size change?如何使高度始终占据窗口的完整高度并能够适应窗口大小的变化?
You can try to get the element's #id
or .class
at runtime and then make the width/Height according to the window width and height:您可以尝试在运行时获取元素的
#id
或.class
,然后根据窗口宽度和高度制作宽度/高度:
$(window).resize(function () {
$('.ui-dialog').css({
'width': $(window).width(),
'height': $(window).height(),
'left': '0px',
'top':'0px'
});
}).resize(); //<---- resizes on page ready
Here is how I was able to "solve" this problem for jQuery UI Ver 1.8.17:以下是我如何为 jQuery UI Ver 1.8.17“解决”这个问题:
After the dialogue has been opened, and assuming that you have captured its id, use the following:打开对话后,假设您已捕获其 id,请使用以下命令:
$("#DlgID").parent().css('height', $(window).height());
The actual height is dictated by the parent of your <div>
containing the dialogue content, hence the reference.实际高度由包含对话内容的
<div>
的父级决定,因此是参考。 You can also use this method to control other properties of the parent.您还可以使用此方法来控制父级的其他属性。
Happy coding!快乐编码!
You can use jquery plugin :您可以使用jquery 插件:
$("#demo").dialog({
width: 500,
height: 300,
dialogClass: "dialog-full-mode" /*must to add this class name*/
});
//initiate the plugin
$(document).dialogfullmode();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.