js scroll to id

150

js scroll to id -

// Js
document.getElementById('id').scrollIntoView();

// JQuery
$('#id')[0].scrollIntoView();

js scroll to id on body -

$("#button").click(function() {
    $('html, body').animate({
        scrollTop: $("#myDiv").offset().top
    }, 2000);
});

Comments

Submit
0 Comments