首页 > 解决方案 > preventDefault 不适用于车轮事件 [已解决]

问题描述

编辑:它通过向模板中的元素添加防止修饰符来工作

我正在开发一个滑块来更改滑轮事件上的幻灯片,我正在限制事件以使其在每次滚动时只工作一次,我有这段代码

  <div
    ref="animated-figure"
    class="animated-figure-wrapper"
  >
     <h1 class="animated-figure__caption">YOU</h1>
  </div>

mounted() {
  this.$refs['animated-figure'].addEventListener('wheel', this.throttle(this.scrollDirection, 800));
},
methods: {
 throttle(func, interval) {
  let lastCall = 0;
  return function() {
    const now = Date.now();
    if (lastCall + interval < now) {
      lastCall = now;
      return func.apply(this, arguments);
    }
  };
 },
 scrollDirection(e) {
  e.preventDefault();

  e.wheelDeltaY > 0
    ? console.log("DOWN")
    : console.log("UP")
  e.stopImmediatePropagation();
 }
}

此处阻止默认设置未按预期工作,并且继续滚动,有什么想法吗?

标签: vue.js

解决方案


推荐阅读