init
This commit is contained in:
31
uni_modules/nutui-uni/components/_hooks/useLockScroll.ts
Normal file
31
uni_modules/nutui-uni/components/_hooks/useLockScroll.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
let count = 0
|
||||
|
||||
const CLSNAME = 'nut-overflow-hidden'
|
||||
|
||||
export function useLockScroll(isLock: () => boolean) {
|
||||
const lock = () => {
|
||||
if (isLock()) {
|
||||
try {
|
||||
!count && document.body.classList.add(CLSNAME)
|
||||
count++
|
||||
}
|
||||
catch (error) {
|
||||
console.error(error)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const unlock = () => {
|
||||
if (isLock() && count) {
|
||||
try {
|
||||
count--
|
||||
!count && document.body.classList.remove(CLSNAME)
|
||||
}
|
||||
catch (error) {
|
||||
console.error(error)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return [lock, unlock]
|
||||
}
|
||||
Reference in New Issue
Block a user