Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cassandra/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 设置div';根据视口的大小调整视图或剖面_Jquery_Css_Html - Fatal编程技术网

Jquery 设置div';根据视口的大小调整视图或剖面

Jquery 设置div';根据视口的大小调整视图或剖面,jquery,css,html,Jquery,Css,Html,我在使用css/javascript时遇到了问题,我想将页面的许多部分设置为浏览器窗口的确切高度和宽度。如果他们调整了浏览器窗口id,也可以调整部分。我想要的是一个类似的效果 Javascript $(document).ready(function() { $('section').css('minHeight',$(window).height() + 'px'); }); CSS 请尝试以下代码: jQuery $(window).resize(function() {

我在使用css/javascript时遇到了问题,我想将页面的许多部分设置为浏览器窗口的确切高度和宽度。如果他们调整了浏览器窗口id,也可以调整部分。我想要的是一个类似的效果

Javascript

$(document).ready(function() {  
    $('section').css('minHeight',$(window).height() + 'px');
});
CSS


请尝试以下代码:

jQuery

$(window).resize(function() {
    calculateSectionContainerHeight();
});

$(document).ready(function (){
    calculateSectionContainerHeight();
});

 // function to calculate section container height
 function calculateSectionContainerHeight() {

     var docHeight =  $(document).height();  

     // setting the section container height.
     $('#section-container').height(sectionHeight + "px");
  }
CSS

@bach3如果您发现任何答案有用,请向上投票,如果答案正确,请接受。这将有助于从未回答问题列表中删除该问题
$(window).resize(function() {
    calculateSectionContainerHeight();
});

$(document).ready(function (){
    calculateSectionContainerHeight();
});

 // function to calculate section container height
 function calculateSectionContainerHeight() {

     var docHeight =  $(document).height();  

     // setting the section container height.
     $('#section-container').height(sectionHeight + "px");
  }
#section-container {
    width:100%;
}