html onclick scroll to div code example
Example 1: how can when click buton scrool to another elemtn
$("button").click(function() {
$('html,body').animate({
scrollTop: $(".second").offset().top},
'slow');
});
Example 2: scroll to specific div
$(window).scroll(function() {
$('html, body').animate({
scrollTop: $("#myDiv").offset().top
}, 2000);
});
Example 3: how to add scroll to div onclick
$("button").click(function() {
$('html,body').animate({
scrollTop: $(".second").offset().top},
'slow');
});
Example 4: how to add scroll to div onclick
.first {
width: 100%;
height: 1000px;
background: #ccc;
}
.second {
width: 100%;
height: 1000px;
background: #999;
}