【问题标题】:Change DIV height dynamically based on viewport height in Drupal 7根据 Drupal 7 中的视口高度动态更改 DIV 高度
【发布时间】:2012-05-12 11:15:45
【问题描述】:

我的页面只包含标题和内容。标题大约是 90 像素,我所有的内容都放在一个 DIV 中。有没有办法改变 DIV 的高度以匹配我的视口高度?

【问题讨论】:

    标签: jquery css drupal


    【解决方案1】:

    试试这个

    $("#id_of_content_div").height($(window).height()-$("#header").height());
    

    $(window).height() 是视口高度

    要在调整视口大小时调整内容高度,请使用

    $(window).resize(function(){
        $("#id_of_content_div").height($(window).height()-$("#header").height());
    });
    

    【讨论】:

    • 我还有一个问题.. 我用这段代码创建了一个 js 文件
    • (function($) { $(document).ready(function(){ $(".bcontainer").height($(window).height()-$("#header" )。高度()); }); }); })(jQuery);
    • 我在 mayo.info 中添加了脚本 .. mayo 是我正在使用的主题 .. 不确定我做对了吗?
    • 好的脚本可以运行,谢谢!但是,有没有办法在我调整视口而不重新加载页面时自动更改它?
    • 使用:$(window).resize(function() { $(".bcontainer").height($(window).height()-$("#header").height( )); });为了清楚起见,编辑了我的答案以包含此代码
    猜你喜欢
    • 2011-09-27
    • 1970-01-01
    • 1970-01-01
    • 2020-10-02
    • 2015-09-15
    • 2013-09-11
    • 2014-11-29
    • 2015-06-26
    • 1970-01-01
    相关资源
    最近更新 更多