最简单的方法
在移动端实现:@touchmove.prevent
在PC端实现: @mousewheel.prevent
js实现
function fixedScroll (boolean = false) {
const scrollTopElement = document.documentElement || document.body
const body = document.body
if (boolean) {
body.style.top = `-${scrollTopElement.scrollTop}px`
body.setAttribute('data-height', scrollTopElement.scrollTop)
body.style.position = 'fixed'
} else {
const height = body.getAttribute('data-height')
body.style.position = 'static'
scrollTopElement.scrollTop = height
}
}