0

id="colLeft"ある列の高さを別の列の高さに設定する簡単なコードがありid="colRight"ます。パディングや境界線はありません。

<script type="text/javascript">
    var colLeft = document.getElementById("colLeft");
    var colRight = document.getElementById("colRight");
    colLeft.style.height = colRight.offsetHeight + "px";
</script>

このコードはデスクトップとiPadで正常に機能しますが、私のAndroidフォンでは結果はかなり予測できません。colLeftがはるかに長い場合もあれば、colRightの場合もあり、正常に機能する場合もあります。2つのブラウザで試してみたところ、同じ結果になりました。

私もそれを内部window.onload=function(){...}で試しましたが、結果のばらつきはわずかに少なくなりましたが、それでも完全ではありません。

助けてくれてありがとう。

4

1 に答える 1

0

You can read a bit about offsetHeight here. The important thing to note is that if the content is larger than the viewable area the browser might do funny things with non-scrolling elements. Because this is a phone browser, I am guessing that the issue is that it is miscalculating the column height because it doesn't deal with scrolling elements correctly.

How do you set the height of the first column? If it has a valid height set in the style sheet you could easily do something like this:

colLeft.style.height = colRight.style.height;

If that doesn't work, you may need to set the column height based on the browser window size with something like:

    colLeft.style.height = colRight.style.height = (window.innerHeight - 10) + "px";

Or something similar.

于 2013-01-24T07:11:01.127 に答える