我听说它是offset.width,document.documentElement.clientWidth和window.innerWidth
我很好奇我不能使用jQuery的项目,我应该使用哪种解决方案?
function windowWidth() {
var docElemProp = window.document.documentElement.clientWidth,
body = window.document.body;
return window.document.compatMode === "CSS1Compat" && docElemProp || body && body.clientWidth || docElemProp;
}
Run Code Online (Sandbox Code Playgroud)
拍摄(并从jQuery源进行了稍微修改:
https://github.com/jquery/jquery/blob/master/src/dimensions.js#L42