10000
We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 7993a9c commit b74abb9Copy full SHA for b74abb9
ScrollBarOffset/index.js
@@ -0,0 +1,14 @@
1
+export function addScrollBarOffsetWidth(className) {
2
+ const isTouchDevice = "ontouchstart" in window
3
+ if (!isTouchDevice) { // 如果是触摸屏则滚动条不占据空间 不进行操作
4
+ let observer = new MutationObserver(mutations => {
5
+ const flag = mutations.some(mutation => mutation.target.className == className) // 判断是否含有目标属性
6
+ if (flag) {
7
+ document.querySelector('body').style.paddingRight = 17 + 'px' // 有overflow属性则给body添加padding-right
8
+ } else {
9
+ document.querySelector('body').style.paddingRight = 0 + 'px' // 没有则归零
10
+ }
11
+ })
12
+ observer.observe(document.querySelector('body'), { attributes: true, attributeFilter: ['class'] })
13
14
+}
0 commit comments