-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: 增加 prop: urlMapper & 优化锁定 body 滚动
- Loading branch information
zhuwenhan
committed
Feb 15, 2020
1 parent
d4759fb
commit fafd0ac
Showing
6 changed files
with
98 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
export function forbiddenBodyScroll () { | ||
let scrollBarWidth = window.innerWidth - document.documentElement.offsetWidth | ||
let scrollBarHeight = window.innerHeight - document.documentElement.offsetHeight | ||
if (scrollBarWidth || scrollBarHeight) { | ||
document.body.style.overflow = 'hidden' | ||
// 给 body 添加边距防止抖动 | ||
const { style } = document.body | ||
let { paddingRight, paddingBottom } = getComputedStyle(document.body) | ||
|
||
let initPaddingRight = style.paddingRight | ||
let initPaddingBottom = style.paddingBottom | ||
|
||
if (scrollBarWidth) { | ||
paddingRight = parseInt(paddingRight) || 0 | ||
document.body.style.paddingRight = paddingRight + scrollBarWidth + 'px' | ||
} | ||
if (scrollBarHeight) { | ||
paddingBottom = parseInt(paddingBottom) || 0 | ||
document.body.style.paddingBottom = paddingBottom + scrollBarHeight + 'px' | ||
} | ||
|
||
return function restoreBodyScroll () { | ||
document.body.style.overflow = '' | ||
document.body.style.paddingRight = initPaddingRight | ||
document.body.style.paddingBottom = initPaddingBottom | ||
} | ||
} else { | ||
return function () {} | ||
} | ||
} |