Home > Web Front-end > JS Tutorial > 脚本控制自适应高度的缩短问题_javascript技巧

脚本控制自适应高度的缩短问题_javascript技巧

WBOY
Release: 2016-05-16 19:08:27
Original
1529 people have browsed it

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";
}

我想用脚本来控制自适应高度,我用上面的代码控制了左列和右列的自适应高度。
可是有的页面因为内容多被撑得挺长,有的页面内容少,用上面的代码不能缩短了!
我就是想在访问内容少的时候,内容还能再缩回来,代码应该怎么写呢?谢谢了!

复制代码 代码如下:

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";
}

解答:
在IE和Opera里,DIV的style.overflowY的默认值是"auto",上面的代码不会有问题。

在Firefox和Safari里,DIV的style.overflowY的默认值是""(相当于"hidden"),所以你直接用上面代码的话,会出错。需要人为调整style.overflowY="auto"。
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template