如何使用 jQuery 获取 div 完整内容的高度? [英] How do I get the height of a div's full content with jQuery?

查看:34
本文介绍了如何使用 jQuery 获取 div 完整内容的高度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建自己的滚动条.我已经尝试了大部分 jquery 滚动条插件,但似乎没有一个适合我,所以我决定创建自己的.我有一个带有可滚动内容的溢出区域.如果我能够计算出可滚动内容区域的高度,我就可以让滚动条工作.我试过 .scrollHeight() 并且浏览器甚至无法识别它.溢出区有一个固定的位置.

解决方案

scrollHeightDOM 对象,不是函数:

<块引用>

元素滚动视图的高度;它包括元素填充但不包括它的边距.

鉴于此:

<div id="x" style="height: 100px; overflow: hidden;"><div style="height: 200px;">薄煎饼

这将产生 200:

$('#x')[0].scrollHeight

例如:http://jsfiddle.net/ambiguous/u69kQ/2/(在 JavaScript 控制台打开的情况下运行).

I am trying to create my own scroll bars. I have tried most of the jquery scrollbar plugins and none of them seem to work for me, so I decided to create my own. I have an overflow area with scrollable content. I can get the scrollbar to work if I am able to figure out the height of the scrollable content area. I have tried .scrollHeight() and the browser doesn't even recognize it. The overflow area has a fixed position.

解决方案

scrollHeight is a property of a DOM object, not a function:

Height of the scroll view of an element; it includes the element padding but not its margin.

Given this:

<div id="x" style="height: 100px; overflow: hidden;">
    <div style="height: 200px;">
        pancakes
    </div>
</div>

This yields 200:

$('#x')[0].scrollHeight

For example: http://jsfiddle.net/ambiguous/u69kQ/2/ (run with the JavaScript console open).

这篇关于如何使用 jQuery 获取 div 完整内容的高度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
其他开发最新文章
热门教程
热门工具
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆