模态窗打开防止底层滑动

let bodyEl = document.body
let top = 0
export function stopBodyScroll(isFixed: boolean){
  if (isFixed) {
    top = window.scrollY
    bodyEl.style.position = 'fixed'
    bodyEl.style.top = -top + 'px'
    document.body.style.overflow = 'hidden'
  } else {
    bodyEl.style.position = ''
    bodyEl.style.top = ''
    window.scrollTo(0, top) // 回到原先的top
    document.body.style.overflow = 'scroll'
  }
}

 

你可能感兴趣的:(js,js)