Jquery 设置div';根据视口的大小调整视图或剖面
我在使用css/javascript时遇到了问题,我想将页面的许多部分设置为浏览器窗口的确切高度和宽度。如果他们调整了浏览器窗口id,也可以调整部分。我想要的是一个类似的效果 JavascriptJquery 设置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() {
$(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%;
}