解决在Firefox(<21)下获取 scroll[Width|Height] 值不正确的bug
2014-06-13 00:00
411 查看
摘要: 在Firefox版本< 21下,获取DOM对象的 scrollWidth 和 scrollHeight 的值不正确,都是等于 clientWidth 或 clientHeight。
在Firefox版本< 21中,js获取DOM对象的 scrollWidth 和 scrollHeight 的值不正确,都是等于 clientWidth 或 clientHeight。
https://bugzilla.mozilla.org/show_bug.cgi?id=833542
解决方法如下:
jQuery写法:
在Firefox版本< 21中,js获取DOM对象的 scrollWidth 和 scrollHeight 的值不正确,都是等于 clientWidth 或 clientHeight。
https://bugzilla.mozilla.org/show_bug.cgi?id=833542
解决方法如下:
var ele = document.getElementById('xxx'); // 1. 先把需要获取DOM对象的overflow强制指定为hidden ele.style.overflow = 'hidden'; // 2. 然后再获取对象的 scrollWidth 或 scrollHeight var sw = ele.scrollWidth; // 3. 最后恢复DOM对象的原始oveflow属性 ele.style.overflow = 'visible'; alert("clientWidth="+ ele.clientWidth + ", scrollWidth="+ sw);
jQuery写法:
var ele = $('xxxx'); var sw = ele.css('overflow', 'hidden')[0].scrollWidth; ele.css('overflow', 'visible'); alert("clientWidth="+ ele[0].clientWidth + ", scrollWidth="+ sw);
相关文章推荐
- Android解决获取控件Width和Height为0的问题
- BitmapImage 获取网络图片,Width和Height都为1的解决办法。
- 解决在onCreate()过程中获取View的width和Height为0的4种方法
- 解决在onCreate()过程中获取View的width和Height为0的方法
- 解决在onCreate()过程中获取View的width和Height为0的4种方法
- Android解决获取控件Width和Height为0的问题
- 解决在onCreate()过程中获取View的width和Height为0的4种方法
- 实现杂记(27):解决在onCreate()过程中获取View的width和Height为0的4种方法
- 解决在onCreate()过程中获取View的width和Height为0的4种方法
- 解决在onCreate()过程中获取View的width和Height为0的4种方法
- js获取浏览器基本信息:document.body.clientWidth/clientHeight/scrollWidth/scrollTop。
- js获取浏览器基本信息:document.body.clientWidth/clientHeight/scrollWidth/scrollTop
- 获取View的width,height的正确方式
- 关于chrome,firefox中img.width=0,img.height=0的解决方法
- 解决在onCreate()过程中获取View的width和Height为0的4种方法
- js获取浏览器基本信息:document.body.clientWidth/clientHeight/scrollWidth/scrollTop。(转)
- 在onCreate()过程中获取View的width和Height为0的4种解决方法
- firefox ie chrome 设置单元格宽度 td width 有bug,不能正常工作。以下方式可以解决
- 解决在onCreate()过程中获取View的width和Height为0的4种方法
- 解决在onCreate()过程中获取View的width和Height为0的4种方法