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
Generate random password for form field on click using JavaScript
JavaScript sort multi dimensional array on specific columns
How to declare multiple variables in one statement in Javascript?
How to set checkbox and radio option checked on load with jQuery?
Get largest number from each sub-arrays
How to get selected text from a select box using jQuery?