如何使用 JQuery 调整窗口大小?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6709408/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to resize a window using JQuery?
提问by The Light
JQuery has an event called resize using which you can add an event handler when the window is resized e.g.
JQuery 有一个名为 resize 的事件,您可以使用它在调整窗口大小时添加一个事件处理程序,例如
$(window).resize(function () {
// code here
});
What I'd need is to resize the window using a JQuery command; would that be possible?
我需要的是使用 JQuery 命令调整窗口大小;那可能吗?
e.g. $(window).resize(-1, -1); // to decrease/increase the width and height of the window
例如 $(window).resize(-1, -1); // 减少/增加窗口的宽度和高度
Thanks
谢谢
回答by ShankarSangoli
Try to use this, its a pure javascript no JQuery involved.
尝试使用它,它是一个纯 javascript,不涉及 JQuery。
window.resizeTo(width, height);
回答by Kevin Burton
sorry looks like that binds an event handler to the "resize" JavaScript event, or trigger that event on an element.
抱歉看起来将事件处理程序绑定到“调整大小”JavaScript 事件,或在元素上触发该事件。