I'm trying to make something in HTML for school that scrolls down to the next section when the down arrow is pressed.
Currently, the site scrolls down the number of pixels outputted by ((window.innerHeight+(window.innerHeight*0.1))+1)
.
Here is my Java Script code:
document.onkeydown = checkKey;
function checkKey(e) {
e = e || window.event;
if (e.keyCode == '40') {
document.getElementById("mainbody").scrollBy({
top: ((window.innerHeight+(window.innerHeight*0.1))+1),
behavior: 'smooth'
});
}
}
The code makes scrolls down way too fast. Is there some way to scroll down slowly the same number of pixels in pure Java Script?
Thanks for any ideas.