Scroll to Div
<!DOCTYPE html>
<html lang="en">
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js"></script>
<script>
$(document).ready(function (){
$("#click").click(function (){
$('html, body').animate({
scrollTop: $("#div1").offset().top
}, 2000);
});
});
</script>
</head>
<body>
<div id="div1" style="height: 1000px; width 100px">
Test
</div>
<br/>
<div id="div2" style="height: 1000px; width 100px">
Test 2
</div>
<button id="click">Click me</button>
</body>
</html>
Most Helpful This Week
How to scroll page to 1000px from top on page load using jQuery?
How to define Global Variable in JavaScript?
ES6 method of declaration multiple variables in one line
Generate random password for form field on click using JavaScript
How to check a variable is undefined in JavaScript?
JavaScript calculate Fahrenheit from Celsius
JavaScript example to change image on click
How to change text color on click using JavaScript?
jQuery show input text inside div after on click event
jQuery move multi select values from one to another multi select list