對不起,如果這是一個小問題,但我是新來的JavaScript。我正在爲具有全寬彩色背景的網頁編寫代碼。本質上,我試圖做的是檢測窗口的高度,然後確保顏色塊是窗口的大小。該功能在頁面加載時效果很好。jQuery窗口調整大小功能不起作用
問題是當我縮小窗口時,div高度不隨窗口大小而改變。我會遇到各種各樣的錯誤,比如從div後面伸出的圖形。
我想我缺少的是一種方法來檢測每個div內的高度,並相應地調整高度。
你可以看到它是如何工作的http://pressshoppr.com
下面的代碼:
$(function(){
var windowH = $(window).height();
if(windowH > wrapperH) {
$('.fullWidthSectionBG').css({'height':($(window).height())+'px'});
$('.fullWidthSectionBGFirst').css({'height':($(window).height())-120+'px'});
}
$(window).resize(function(){
var windowH = $(window).height();
var wrapperH = $('.fullWidthSectionBG').height();
var newH = wrapperH + differenceH;
var truecontentH = $('.fullWidthSection').height();
if(windowH > truecontentH) {
$('.fullWidthSectionBG').css('height', (newH)+'px');
$('.fullWidthSectionBGFirst').css('height', (newH)-120+'px');
}
});
});
你爲什麼不只是使用'$(窗口).height()'在你調整大小功能呢?如果它在第一頁加載時工作正常,我不知道爲什麼在窗口大小調整時需要對高度進行任何計算。 – Samsquanch