offsetWidth的浏览器兼容问题。

mizchh 2012-04-28 03:31:34
offsetWidth在IE和火狐上都正常,能正常控制宽度。

但是在Chrome(谷歌浏览器)和遨游浏览器上用JS的offsetWidth来控制宽度时,控制不了,页面上的宽度是0.

急,求解,在线等...

...全文
728 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
jychsh 2012-05-09
  • 打赏
  • 举报
回复
如果不是浏览器兼容的问题,
请检查一下css文件的display和z-index设置。
jychsh 2012-05-09
  • 打赏
  • 举报
回复
我之前也遇到类似的问题。
JQ加载了两个层,由于css的z-index值设置,导致无法取到相对于父窗口的偏移量。
d945332077 2012-05-08
  • 打赏
  • 举报
回复
在jquery低版本中不支持innerHeight
mizchh 2012-05-08
  • 打赏
  • 举报
回复
求解,在线等。。。
mizchh 2012-05-07
  • 打赏
  • 举报
回复
var l_items_width = 0;

l_items_width += this.parentNode.parentNode.offsetWidth;

context.nav.find('.ad-thumb-list').css('width', l_items_width + 'px');


整个的代码太长了,是个JQ插件。
001007009 2012-04-29
  • 打赏
  • 举报
回复
楼主把完整的代码 贴出来,如果很多,那么模拟一个页面出来,大家好调试
mizchh 2012-04-28
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 的回复:]

引用 3 楼 的回复:

引用 1 楼 的回复:

你怎样获取的?


用innerHTML输出。

贴代码。。。
[/Quote]

var l_items_width = 0;

l_items_width += this.parentNode.parentNode.offsetWidth;

context.nav.find('.ad-thumb-list').css('width', l_items_width + 'px');


mizchh 2012-04-28
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 的回复:]

根据这个自己改吧~!
JScript code

function getWindowSize() {
if (self.innerHeight) { // WEBKIT
return { 'width':self.innerWidth, 'height':self.innerHeight };
} else if (document.documentElem……
[/Quote]


l_items_width += this.parentNode.parentNode.offsetWidth;

这是我的JS控制代码。

三石-gary 2012-04-28
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 的回复:]

引用 1 楼 的回复:

你怎样获取的?


用innerHTML输出。
[/Quote]
贴代码。。。
mizchh 2012-04-28
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 的回复:]

你怎样获取的?
[/Quote]

用innerHTML输出。
豪情 2012-04-28
  • 打赏
  • 举报
回复
根据这个自己改吧~!

function getWindowSize() {
if (self.innerHeight) { // WEBKIT
return { 'width':self.innerWidth, 'height':self.innerHeight };
} else if (document.documentElement && document.documentElement.clientHeight) { // IE standards 模式
return {
'width' :document.documentElement.clientWidth,
'height':document.documentElement.clientHeight
};
} else if (document.body) { // IE quirks 模式
return {
'width' :document.body.clientWidth,
'height':document.body.clientHeight
};
}
}
三石-gary 2012-04-28
  • 打赏
  • 举报
回复
你怎样获取的?

87,910

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧