jquery - 相当于 jQuery 的 $(window).width 的原始 JavaScript 是什么?

标签 jquery width

我听说是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;
}

取自 jQuery 源代码(并稍加修改:

https://github.com/jquery/jquery/blob/master/src/dimensions.js#L42

关于jquery - 相当于 jQuery 的 $(window).width 的原始 JavaScript 是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8221172/

相关文章:

javascript - 围绕 javascript/html 数据选项的 if 语句

javascript - 使用 jQuery 选择所有复选框

jquery - 如何更改链式 .then() 函数中的 promise 解析结果

button - JavaFX TabPane 宽度和按钮宽度不匹配

php - 不同宽度的首页和文章页

javascript - jquery - 获取尚未应用的类的 CSS 属性值

Jquery ajax从https到http的调用

jquery - 使用 jquery AND 规则进行动态表单字段验证

html - 我们如何使div根据其内容自动取宽度

css - 调整表格大小