diff --git a/js/utils/getScrollbarWidth.ts b/js/utils/getScrollbarWidth.ts index ede1cbd347..933d4ce93b 100644 --- a/js/utils/getScrollbarWidth.ts +++ b/js/utils/getScrollbarWidth.ts @@ -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; }