如何在窗口调整大小时更改高度div? [英] How to change height div on window resize?

查看:107
本文介绍了如何在窗口调整大小时更改高度div?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的网站上有一个div,应该是窗口的高度. 这就是我得到的:

I have a div on my website that should be the height of the window. This is what i got:

    $(document).ready(function() {
    var bodyheight = $(document).height();
    $("#sidebar").height(bodyheight);
});

但是,当调整窗口大小时,它不会自动更改吗?有谁知道如何解决这个问题?

However, it does not automatically change when the window is resized? Does any body know how to fix this?

谢谢

推荐答案

您还需要在resize事件中执行此操作,请尝试以下操作:

You also need to do that in resize event, try this:

$(document).ready(function() {
    $(window).resize(function() {
        var bodyheight = $(this).height();
        $("#sidebar").height(bodyheight);
    }).resize();
});

这篇关于如何在窗口调整大小时更改高度div?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆