英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论