是否可以使用 JavaScript 或 jQuery 获取窗口对象尺寸并创建函数来调整浏览器窗口的 div
高度?
最佳答案
您可以绑定(bind)到 resize
事件,以便...重新调整元素的大小:
//bind event handler to the `resize` event
$(window).on('resize', function () {
//cache the window object for use in this function
var $this = $(this);
//set the height of my object to the height of the window
$('#my-object').height($this.height());
//trigger a window resize to initialize the object's height
}).trigger('resize');
$this
指的是 window
对象。
请注意,.on()
是 jQuery 1.7 中的新内容,并在本例中取代了贬值的 .bind()
。
关于javascript - 如何使用 javascript 或 jquery 在浏览器窗口中调整 div 的大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8143558/