相当于 jQuery 的 $(window).width 的原始 JavaScript 是什么?
我听说它是 offset.width 、 document.documentElement.clientWidth 和 window.innerWidth
我对无法使用 jQuery 的项目很好奇,我应该使用哪种解决方案?
I've heard it's offset.width, document.documentElement.clientWidth, and window.innerWidth
I'm curious for projects which I cannot use jQuery on, which solution I should use?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
取自 jQuery 源(并稍作修改:
https://github .com/jquery/jquery/blob/master/src/dimensions.js#L42
Taken (and modified slightly from the jQuery source:
https://github.com/jquery/jquery/blob/master/src/dimensions.js#L42
亲自查看。
它使用不同的东西。 document.documentElement.clientWidth 就是其中之一。
也可以使用 document.body.clientWidth
See for yourself.
It uses different things. document.documentElement.clientWidth is among them.
It can also use document.body.clientWidth
上述
属性返回与
$( window ).width()
相同的值。现场演示: http://jsfiddle.net/Jukh9/1/show/
然而,IE8 并没有实现这个属性...
This
The above property returns the same value as
$( window ).width()
.Live demo: http://jsfiddle.net/Jukh9/1/show/
However, IE8 does not implement this property...