I’m currently building a website that can scroll down or up like the browser already installed Vimium plugin. But I found that vimium scroll animation speed is different from window.scrollBy(), neither pass in “instant” or “smooth” will satisfy my requirement, “smooth” is too slow and have a wired timing function. I want to use wasd to scroll my website and the animation should be the same like pressing spacebar to scroll down.
import "./App.css";
import { useRef, useEffect } from "react";
export default function App() {
const appRef = useRef(null);
useEffect(() => {
window.addEventListener("keydown", (e) => {
if (e.keyCode === 87) {
window.scrollBy(0, -300);
} else if (e.keyCode === 83) {
window.scrollBy(0, 300);
}
});
});
return <div ref={appRef}>Lorem2000</div>
}