javascript - 如何使用 javascript 或 jquery 在浏览器窗口中调整 div 的大小

标签 javascript jquery

是否可以使用 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/

相关文章:

javascript - 一种更快、更干净的方法来替换 JavaScript 中的绑定(bind)

javascript - 带条件的开关盒

javascript - 命名一个按钮javascript

javascript - 响应表不显示列值

javascript - 将 findAll 与 ownToMany 关联序列化

javascript - React-Native 与 Redux 动态数据源

javascript - 暂时禁用js/css资源

javascript - 创建随机问题和答案 javascript

javascript - 如何使用 Bootstrap 横幅验证文本框

javascript - 在表单提交时维护 div 中的滚动位置 - Django