FireFox中的scrollHeight属性 [英] scrollHeight property in FireFox

查看:107
本文介绍了FireFox中的scrollHeight属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究一个函数来检测DIV元素中的文本是否会溢出。在这方面,我有一个可以在Chrome和IE中使用的函数,它将元素的scrollHeight和clientHeight属性进行比较。

然而在FireFox中,这两个属性(以及offsetHeight)总是报告相同的数字,恰好是div元素的高度。

如果我将'overflow:auto'添加到div,我会从scrollHeight属性获得准确的结果样式。但是显示滚动条对于我正在开发的项目来说并不是一个可接受的解决方案。

有什么建议?



当元素的内容不
生成一个垂直滚动条,那么
其scrollHeight属性等于
其clientHeight属性。


https://developer.mozilla.org/zh/DOM/element.scrollHeight






我知道这不是干净的,但是你可以这样做吗?

  e.style.overflow =scroll; 
var scrollHeight = e.scrollHeight;
e.style.overflow =隐藏;

用户看不到,因为只有在当前没有运行javascript的情况下页面才会重新绘制。 / p>

I'm working on a function to detect whether text inside of a DIV element would overflow. In this regard I have a function working in both Chrome and IE that compares the element's scrollHeight to the clientHeight attributes.

However in FireFox both attributes (as well as offsetHeight) always report the same number which happens to be the height of the div element.

I do get accurate results from the scrollHeight property if I add 'overflow:auto' to the div style. But displaying the scrollbar isn't an acceptable solution for the project I'm working on.

Any suggestions?

解决方案

That's documented behaviour:

When an element's content does not generate a vertical scrollbar, then its scrollHeight property is equal to its clientHeight property.

https://developer.mozilla.org/en/DOM/element.scrollHeight


I know that it isn't clean, but could you do something like this?

e.style.overflow = "scroll";
var scrollHeight = e.scrollHeight;
e.style.overflow = "hidden";

The user can't see that because the page only gets redrawn when no javascript is currently running.

这篇关于FireFox中的scrollHeight属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆