javascript - 如何使用 jQuery 设置内容高度 – 在小窗口尺寸下 chop

标签 javascript jquery window height

我无法让它发挥作用。目前,它正在将section[role=“main”]的大小调整为正确的高度,但是当您将窗口大小调整为较小的尺寸时,它会被切断。

<script type="text/javascript">
    $(function(){
        $('section[role="main"]') .css({'height': (($(window).height()))+'px'});
        $(window).resize(function(){
            $('section[role="main"]') .css({'height': (($(window).height()))+'px'});
        });
    });
</script>

我还想知道如何补偿页脚的高度?截至目前,它将页脚推离屏幕。

感谢您的帮助!

所以它应该看起来像这样,Patrick(已更新)

    <script type="text/javascript">
        $(function(){
            $(window).resize(function(){
                var winheight = $(window).height();
                var heightMinusFooter = winheight - jQuery("#footer").height();
                $('section[role="main"]') .css({'height': heightMinusFooter+'px'});
            });
        });
    </script>

最佳答案

从窗口高度中减去页脚高度,然后应用。

$(window).resize(function(){
    var winheight = $(window).height();
    var heightMinusFooter = winheight - jQuery("#footer").height();
    $('section[role="main"]') .css({'height': heightMinusFooter+'px'});
});

关于javascript - 如何使用 jQuery 设置内容高度 – 在小窗口尺寸下 chop ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18047840/

相关文章:

javascript - 显示 Javascript 代码源

javascript - 关于 php/javascript 中的日期选择器

javascript - 我使用 .done() 不正确,没有按预期返回值

wpf - WPF中如何延迟窗口关闭

visual-studio-2008 - VS2008 如何摆脱 "Error List"窗口

javascript - Express.js不是 `res.send`集吗?

javascript - 将 native 使用与开发/生产 ios 目标应用程序 react

javascript - 当窗口宽度达到865px时重新启动greensock(JS)动画

jquery - 使用 Jquery,从文本字段中提取文本并将其放入无序列表 onClick

jquery - 从另一个页面链接到固定标题下的 anchor