I need that when the user presses the DOWN button (down) on the keyboard, it goes to a div in the same way as with a scrollTop. Has anyone done something like this using jQuery?

It would be something like this?

$(window).on('keydown', function (e) {
    if (e.which != 40) return false;
    var posicao = $('.homeBaixoRodapeTexto1').position().top;
    $('html, body').stop().animate({
        scrollTop: posicao
    }, 1500);
});
有帮助吗?

解决方案

I believe you want .offset().top instead of .position().top.

$(window).on('keydown', function (e) {

    if (e.which != 40) return true;

    e.preventDefault();

    var posicao = $('.homeBaixoRodapeTexto1').offset().top;

    $('html, body').stop().animate({
        scrollTop: posicao
    }, 1500);

});

You have to be real careful with this. You're essentially breaking navigation with the keyboard.

Here's a small demo: http://jsbin.com/xecapoyu/3/edit?js,output

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top