1

現在、html 要素の高さを取得するためにいくつかの問題が発生しています。ウィンドウのサイズが変更されたときに更新されないようです。「height: auto」で html をリセットしようとしましたが、それは役に立たないようです。

幅は正常に機能しますが、高さは更新されません。

この問題の解決策はありますか?

前もって感謝します!

JQuery:

 function UpdateLeftBar() {
    // Reset
    $('html').height('auto');
    // Get the height of the window and minus the header and left top elements
    height = $('html').height() - 85 - 56 + 29;
    width = $('html').width() - 300;
    // Set the div to the new height
    $('#leftContentBottom').css({ 'height': height });
    $('#middleContent.span10').css({ 'width': width });
    console.log(height);
}

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

本当に奇妙なことに、80% の確率で更新されることに気付きましたが、ウィンドウをダブルクリックしてもサイズが変更されません。

修正: HTML の高さを取得する代わりに、ウィンドウの高さを取得する必要があります。これで問題が解決しました。

4

1 に答える 1

1

重複したスレッドを投稿してくれた Huangism のおかげで、私の問題は非常に簡単に解決できました。

解決策は、ウィンドウの高さを取得するために html 要素を使用する代わりに window を使用することです。html は常に更新されるとは限らないようです。

        function UpdateLeftBar() {
    // Get the height of the window and minus the header and left top elements
    height = $(window).height() - 85 - 56;
    width = $('html').width() - 300;
    // Set the div to the new height
    $('#leftContentBottom').css({ 'height': height });
    $('#middleContent.span10').css({ 'width': width });
    console.log(height);
}

$(window).resize(function () {
    UpdateLeftBar();
});
于 2013-07-15T17:37:58.163 に答える