vue.js - 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();
}
}
此处阻止默认设置未按预期工作,并且继续滚动,有什么想法吗?
解决方案
推荐阅读
- opengl - 在另一个图像上添加图像 - OpenTK
- string - 使用像 js 字符串一样的 sed 进行字符串操作?
- css - 分页修复 Wordpress/CSS
- ios - VPIO AUAudioUnit 的 3A 处理不会在 iOS 14 设备上的 RemoteIO 模式下停止
- java - 自定义分叉连接池正在与 java 程序中的公共池一起使用
- mysql - Laravel 7 App 无法上传到 Heroku 云服务
- asp.net - url中带有“json”字符串的属性路由
- javascript - 在需要和运行目录时收到 forEach 错误?
- azure-functions - 逻辑应用 JSON 组合将 JSON 值转换为字符串
- android - recyclerView = (RecyclerView) findViewById(R.id.recyclerView);