Created
October 13, 2020 16:45
-
-
Save mattgperry/87c5b8e03728e4ae079697645480ce49 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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