(禁止 | 允许)屏幕滚动 h5

369 阅读1分钟
function RollFn (evt) {
    evt.preventDefault();
    evt.stopPropagation();
    return false;

}
/** * @desc 禁止屏幕滑动 * @return {null} */
export const noRoll = () => {
    document.body.style.overflow = 'hidden';
    document.body.addEventListener('touchmove', RollFn, { passive: false })
}

/** * @desc 禁止屏幕滑动(解除),页面回滚到原位置 * @return {null} */
export const yesRoll = () => {
    document.body.style.overflow = '';//出现滚动条
    document.body.removeEventListener('touchmove', RollFn, { passive: false })
}