So i got a page with different divs in it and I want to scroll down with the arrow down key to each one, for example
<div id="one">
<div id="two">
<div id="three">
i first tried this
var scrolled = 0;
$("body").keyup(function(e) {
if(e.keyCode == 40) {
scrolled++;
$('body,html').animate({scrollTop: 895 * scrolled}, 700);
}
but this isn't what i want because obviously it won't work correctly on a computer with a different dpi so I tried this
$(document).keydown(function(e) {
e.stopPropagation();
if (e.keyCode == 40) {
e.preventDefault();
$('body').animate({
'scrollTop': $('#one').offset().top}, 800);
}
but i don't know how I could use this code to get to the div with the id #2 ... So could someone help me do that ?
Thanks