原生 JS 和 jQuery 中的尺寸

element

jQuery JS
$(elem).width() border-box: elem.offsetWidth - padding - border
content-box: elem.offsetWidth - padding
$(elem).innerWidth() elem.clientWidth + scrollbar
$(elem).outerWidth() elem.offsetWidth

window

jQuery JS
$(window).width() document.documentElement.clientWidth
$(window).innerWidth() document.documentElement.clientWidth
$(window).outerWidth() window.innerWidth

document

jQuery JS
$(document).width() Math.max(document.body.scrollWidth,
document.documentElement.scrollWidth,
document.body.offsetWidth,
document.documentElement.offsetWidth,
document.documentElement.clientWidth)
$(document).innerWidth()
$(document).outerWidth()

感谢您的阅读,如果您对我的文章感兴趣,可以关注我的博客,我是叙帝利,下篇文章再见!


基于 Angular Material 的中后台管理框架 https://github.com/ng-matero/ng-matero

Angular Material Extensions 扩展组件库 https://github.com/ng-matero/extensions

仿 Windows 照片查看器插件 https://github.com/nzbin/photoviewer

仿 Windows 照片查看器插件 jQuery 版 https://github.com/nzbin/magnify

完美替代 jQuery 的模块化 DOM 库 https://github.com/nzbin/domq

简化类名的轻量级 CSS 框架 https://github.com/nzbin/snack

与任意 UI 框架搭配使用的通用辅助类 https://github.com/nzbin/snack-helper

单元素纯 CSS 加载动画 https://github.com/nzbin/three-dots

有趣的 jQuery 卡片抽奖插件 https://github.com/nzbin/CardShow

悬疑科幻电影推荐 https://github.com/nzbin/movie-gallery

锻炼记忆力的小程序 https://github.com/nzbin/memory-stake

原文地址:https://www.cnblogs.com/nzbin/p/15083217.html