Click And Scroll To Div jQuery

click button and smooth scroll to div

by Vikash Pareek

HTML

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<h1>Click And Scroll To Div</h1>
	<a href="#" class="click-me">Click Me</a>
	<div class="box box-1">
		<p>1-box</p>
	</div>
	<div class="box box-2">
		<p>2-box</p>
	</div>
	<div class="box box-3">
		<p>3-box</p>
	</div>
	<div class="box box-4">
		<p>4-box</p>
	</div>
	<div class="box box-5 mb-50">
		<p>5-box</p>
	</div>

CSS

*{
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}
a{
  text-decoration: none;
}
body{
  font-family: sans-serif;
}
a{
  padding: 10px 20px;
  background: #b68a8e;
  color: #fff;
  border-radius: 10px;
  display: inline-block;
  margin-left: 5em;
}
h1{
  text-align: center;
  margin-top: 50px;
}
.box{
  height: 200px;
  max-width: 90%;
  margin: auto;
  background: #d4bab0;
  margin-top: 5em;
  display: flex;
  justify-content: center;
  align-items: center;
}
.box p{
  font-size: 20px;
  color: #000;
}
.mb-50{
  margin-bottom: 5em;
}

JavaScript

jQuery(document).ready(function(){
  jQuery(".click-me").click(function() {
    jQuery('html,body').animate({
      scrollTop: jQuery(".box-5").offset().top
    }, 1000);
  });
});