I am using this code to allow scroll using keyboard arrows, the issue is that its smooth going downwards but not upwards. I also want it to scroll to each section instead of holding down the arrow. is this possible?
$(document).keydown(function(e) {
switch (e.which) {
case 38: // up
document.body.scrollTop -= 500;
document.documentElement.scrollTop -= 500;
break;
case 40: // down
document.body.scrollDown += 500;
document.documentElement.scrollDown += 500;
break;
default:
return; // exit this handler for other keys
}
});
$(document).ready(function(){
window.focus();
});
body{
height: 2000px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>