Created
May 6, 2022 12:43
-
-
Save worldoptimizer/1a9ac8cb210d513a747ad313ddb93748 to your computer and use it in GitHub Desktop.
This file contains 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
var scrollSpeed = 0; | |
var isScrolling = false; | |
document.addEventListener('keydown', function(e) { | |
if (sidebar.classList.contains('open')) { | |
if (e.shiftKey && e.keyCode === 38) { | |
scrollSpeed *= 1.5; | |
scrollSpeed = Math.min(Math.max(scrollSpeed, -10), -1); | |
if (!isScrolling) { | |
isScrolling = requestAnimationFrame(scroll); | |
} | |
} | |
if (e.shiftKey && e.keyCode === 40) { | |
if (Math.abs(scrollSpeed) < 1) scrollSpeed = 1; | |
scrollSpeed *= 1.5; | |
scrollSpeed = Math.min(Math.max(scrollSpeed, 1), 10); | |
console.log(scrollSpeed) | |
if (!isScrolling) { | |
isScrolling = requestAnimationFrame(scroll); | |
} | |
} | |
} | |
}); | |
function scroll() { | |
if (sidebar.classList.contains('open')) { | |
if (Math.abs(scrollSpeed) > 0.1) { | |
sidebar.scrollTop += scrollSpeed; | |
scrollSpeed *= 0.95; | |
isScrolling = requestAnimationFrame(scroll); | |
} else { | |
scrollSpeed=0; | |
isScrolling = null; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment