Skip to content

Commit

Permalink
chore: 根据不同的容器dom进行获取scroll 的宽度
Browse files Browse the repository at this point in the history
  • Loading branch information
RSS1102 committed Oct 14, 2024
1 parent 993a49c commit 44f9c8a
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions js/utils/getScrollbarWidth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,14 @@ export function getScrollbarWidthWithCSS() {
return scrollbarWidth;
}

// 获取 body 下滚动条宽度
export function getScrollbarWidth() {
return window.innerWidth - document.documentElement.clientWidth;
/**
* @description: Calculate scroll bar width
* @param container Container used to calculate scrollbar width
* @default container: document.body
*/
export function getScrollbarWidth(container: HTMLElement = document.body) {
if (container === document.body) {
return window.innerWidth - document.documentElement.clientWidth;
}
return container.offsetWidth - container.clientWidth;
}

0 comments on commit 44f9c8a

Please sign in to comment.