javascript Jquery,知道带滚动条的 div 的宽度和高度

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10687547/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 10:42:03  来源:igfitidea点击:

Jquery, know width and height of a div with scroll bar

javascriptjqueryhtmlcss

提问by Quaquil

I want have width and height of a full div with scroll using JQuery, but i can only have size of visible content and not size of visible + hidden content of scroll bar.

我想要使​​用 JQuery 滚动的完整 div 的宽度和高度,但我只能拥有可见内容的大小,而不能拥有滚动条的可见 + 隐藏内容的大小。

Anyone knows anyway to have this values (width and height)?

任何人都知道有这个值(宽度和高度)?

<div id="area" class="divLeftCem area">
    <div id="panelArea" class="areaBackground"
        style="width: 1004px; height: 613px; background: #FFFFFF url('Images/background.png') repeat;">
    </div>
</div>

.area
{
    margin-left: 10px;
    width: 1004px;
    height: 613px;
    border: 1px solid #AFAFAF;
    overflow: auto;
    position: absolute;
    top: 145px;
}

PS: Sorry about bad english.

PS:抱歉英语不好。

回答by Sampson

Get the element's .scrollHeight:

获取元素的.scrollHeight

$(".el").get(0).scrollHeight;

? It goes without saying you could use .scrollWidthfor the x-axis as well.

? 不用说,您也可以.scrollWidth用于 x 轴。

Fiddle: http://jsfiddle.net/spN6n/

小提琴:http: //jsfiddle.net/spN6n/