Hi, in this article we will discuss how to perform jquery scroll to div element animation.
To perform that scroll to div element animation we will use jquery inbuilt function animate()
.
And inside the animate() function we will use the scrollTop method.
code of Jquery scroll to div element animation
<button id="goToAbout">About</button>
<div>
<h1>Home</h1>
<p>very long content</p>
</div>
<div id="about">
<h1>About</h1>
<p>very long content</p>
</div>
<script>
$(document).ready(function(){
$("#goToAbout").click(function(){
$('html, body').animate({ scrollTop: $("#about").offset().top }, 200);
});
});
</script>
Learn also: