全栈笔记

Vue 滚动事件穿透解决方案

2020-08-30  本文已影响0人  小贤笔记

移动端

<div class="test" @touchmove.prevent></div>

PC

    // 停止页面滚动
    stopMove() {
      let m = function(e) {
        e.preventDefault();
      };
      document.body.style.overflow = 'hidden';
      document.addEventListener('touchmove', m, { passive: false });
    },
    // 开启页面滚动
    canMove() {
      let m = function(e) {
        e.preventDefault();
      };
      document.body.style.overflow = '';
      document.removeEventListener('touchmove', m, { passive: true });
    }
上一篇 下一篇

猜你喜欢

热点阅读