控制鼠标滚动步进

huangapple go评论71阅读模式
英文:

Control mouse scroll step

问题

I would like my ReactJS application to scroll to screen height at once with each mouse scroll step. How can I set the mouse scroll step manually?
否则,如果这不可能。我想要检测用户的鼠标步进,无论他们使用的设备和浏览器。

英文:

I would like my ReactJS application to scroll to screen height at once with each mouse scroll step. How can I set the mouse scroll step manually?
Otherwise, if this is not possible. I would like to detect the user's mouse step regardless of their device and browser.

答案1

得分: 1

我看不到你的代码,所以很难提供正确的实现。但也许你可以使用类似这样的代码:

const content = document.getElementById("content");
content.addEventListener("wheel", (event) => {
    event.preventDefault();
    let deltaY = event.deltaY;
    content.scrollTop += deltaY / n;
});

event.preventDefault 很简单,它阻止了默认设置。
event.deltaY 给出了当前的滚动速度。如果 n 较大,它将减小滚动速度;如果 n 较小,它将增加滚动速度。
使用 content.scrollTop 你可以设置新的调整后的速度。

我不知道这是否是你要找的,希望能帮助到你。

英文:

I can't see your code, so that makes it hard to provide a correct implementation. But maybe you can use something like this:

const content = document.getElementById("content");
content.addEventListener("wheel", (event) => {
    event.preventDefault();
    let deltaY = event.deltaY;
    content.scrollTop += deltaY / n;
});

event.preventDefault is pretty straight forward, it prevents the default settings.
event.deltaY gives the current scrolling speed. If n is larger it will decrease the scrolling speed, if it is smaller it will increase the scrolling speed.
With content.scrollTop you can set the new adjusted speed.

I don't know if this is what your looking for, hope it helps.

huangapple
  • 本文由 发表于 2023年7月18日 13:25:01
  • 转载请务必保留本文链接:https://go.coder-hub.com/76709717.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定