Function vvheight (){
Var sideleft = document. getElementById ("content-left"). scrollHeight;
Var sideright = document. getElementById ("content-right"). scrollHeight;
LayoutHeight = Math. max (sideleft, sideright );
Document. getElementById ("content-left"). style. height = layoutHeight + "px ";
Document. getElementById ("content-right"). style. height = layoutHeight + "px ";
}
I want to use a script to control the adaptive height. I used the code above to control the adaptive height of the left and right columns.
However, some pages are long because of many content, and some pages have less content, so the code used cannot be shortened!
I just want to reduce the content when there are few accesses. How should I write the code? Thank you!Copy codeThe Code is as follows: function vvheight (){
Var CL = document. getElementById ("content-left ");
Var CR = document. getElementById ("content-right ");
While (parseInt (CL. scrollHeight) = parseInt (CL. style. height) {CL. style. height = parseInt (CL. style. height)-30 + "px "}
Var sideleft = CL. scrollHeight;
While (parseInt (CR. scrollHeight) = parseInt (CR. style. height) {CR. style. height = parseInt (CR. style. height)-30 + "px "}
Var sideright = CR. scrollHeight;
LayoutHeight = Math. max (sideleft, sideright );
CL. style. height = layoutHeight + "px ";
CR. style. height = layoutHeight + "px ";
}
Answer:
In IE and Opera, the default value of style. overflowY of DIV is "auto", and the above Code will not be faulty.
In Firefox and Safari, the default value of style. overflowY of DIV is "" (equivalent to "hidden"). Therefore, if you use the above Code directly, an error will occur. Manually adjust style. overflowY = "auto ".Xmlns = "http://www.w3.org/1999/xhtml">
Content left
Content left
Content left
Content left
Content left
Content left
Content left
Content left
Content left
Content left
Content left
- 55 × 65
- 60 × 80
- 90 × 90
- 110 × 73
- 118x53
- 146x53
- 170 × 65
- Others
Content 1
Content 1
Content 1
Content 1
Content 1
Content 1
Content 1
Content 1
Content 1
Content 1
Content 1
Content 1
Content 1
Content 1
Content 1
Content 1
Content 1
Content 1
Content 1
Content 1
Content 1
Content 1
Content 1
Content 1
Content 2
Content 2
Content 2
Content 2
Content 2
Content 2
Content 2
Content 2
Content 3
Content 3
Content 3
Content 3
Content 3
Content 3
Content 3
Content 3
Content 3
Content 3
Content 3
Content 3
Content 3
Content 3
Content 3
Content 3
Content 4
Content 4
Content 4
Content 4
Content 4
Content 4
Content 4
Content 4
Content 4
Content 4
Content 4
Content 4
Content 4
Content 4
Content 4
Content 4
Content 4
Content 4
Content 4
Content 4
Content 4
Content 4
Content 4
Content 4
Content 4
Content 4
Content 4
Content 4
Content 4
Content 4
Content 4
Content 4
Content 4
Content 4
Content 4
Content 4
Content 4
Content 4
Content 4
Content 4
Content 4
Content 4
Content 4
Content 4
Content 4
Content 4
Content 4
Content 4
Content 4
Content 4
Content 4
Content 4
Content 4
Content 4
Content 4
Content 5
Content 5
Content 5
Content 5
Content 5
Content 5
Content 5
Content 5
Content 5
Content 5
Content 5
Content 5
Content 5
Content 5
Content 5
Content 5
Content 5
Content 5
Content 5
Content 5
Content 5
Content 5
Content 5
Content 5
Content 5
Content 5
Content 5
Content 5
Content 6
Content 6
Content 6
Content 6
Content 6
Content 6
Content 7
Content 7
Content 7
Content 7
Content 7
Content 7
Content 7
Content 7
Content 7
Content 7
Content 7
Content 7
Content 7
Content 7
Content 7
Content 7
Content 7
Content 7
Content 7
Content 7
Content 7
Content 7
Content 7
Content 7
Content 7
Content 7
Content 7
Content 7
Content 7
Content 7
Content 7
Content 7
Content 7
Content 7
Content 7
Content 7
Content 7
Content 7
Content 7
Content 7
Content 7
Content 7
Content 7
Content 7
Content 7
Content 7
Content 7
Content 7
Content 7
Content 7
Content 7
Content 7
Content 7
Content 7
Content 7
Content 7
Content 7
Content 7
Content 7
Content 7
Content 7
Content 7
Content 7
Content 7
Content 7
Content 7
Content 7
Content 7
Content 7
Content 7
Content 7
Content 7
Content 7
Content 7
Content 7
Content 7
Content 7
Content 7
Content 7
Content 7
Content 7
Content 7
Content 7
Content 7
Content 7
Content 7
Content 7
Content 7
Content 7
Content 7
Content 7
Content 7
Content 7
Content 7
Content 7
Content 7
Content 7
Content 7
Content 7
Content 7
Content 7
Content 7
Content 8
Content 8
Content 8
Content 8
Content 8
Content 8
Content 8
Content 8
Content 8
Content 8
Content 8
Content 8
Content 8
Content 8
Content 8
Content 8
Content 8
Content 8
Content 8
Content 8
Content 8
Content 8
Content 8
Content 8
Content 8
Content 8
Content 8
Content 8