Skip to content

Instantly share code, notes, and snippets.

@mattgperry
Created October 13, 2020 16:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattgperry/87c5b8e03728e4ae079697645480ce49 to your computer and use it in GitHub Desktop.
Save mattgperry/87c5b8e03728e4ae079697645480ce49 to your computer and use it in GitHub Desktop.
import { useEffect } from "react";
function handleSpace(event: KeyboardEvent) {
if (event.key === " ") {
event.preventDefault();
const delta = event.shiftKey ? -window.innerHeight : window.innerHeight;
window.scrollTo(0, window.scrollY + delta);
}
}
export function FullScreenSpaceJump() {
useEffect(() => {
window.addEventListener("keypress", handleSpace);
return () => window.removeEventListener("keypress", handleSpace);
}, []);
return null;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment