3 Star 54 Fork 14

Yaohaixiao / dom.js

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
getScrollbarWidth.js 718 Bytes
一键复制 编辑 原始数据 按行查看 历史
import isElement from './isElement'
/**
* 获取浏览器或者 DOM 元素纵向滚动条的宽度
* ========================================================================
* @method getScrollbarWidth
* @since 1.4.0
* @see https://developer.mozilla.org/zh-CN/docs/Web/API/Window/innerWidth
* @return {number}
*/
const getScrollbarWidth = (el) => {
let innerWidth = 0
let clientWidth = 0
if (!el) {
innerWidth = window.innerWidth
clientWidth = document.documentElement.clientWidth
} else {
if (isElement(el)) {
innerWidth = el.offsetWidth
clientWidth = el.clientWidth
}
}
return innerWidth - clientWidth
}
export default getScrollbarWidth
JavaScript
1
https://gitee.com/yaohaixiao/dom.js.git
git@gitee.com:yaohaixiao/dom.js.git
yaohaixiao
dom.js
dom.js
main

搜索帮助