I am working on this demo. Why am I not able to animate the #box-2
div to top on click?
$('#box-2').animate({scrollTop : 0},700);
$("#box-2").on("click", function(){
$('#box-2').animate({scrollTop : 0},700);
});
body, html {
width: 100%;
height: 100%; }
.box{
height: 100vh;
}
#box-1{
background:khaki;
}
#box-2{
background:red;
}
#box-3{
background:green;
}
#box-4{
background:orange;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" integrity="sha384-GJzZqFGwb1QTTN6wy59ffF1BuGJpLSa9DkKMp0DgiMDm4iYMj70gZWKYbI706tWS" crossorigin="anonymous">
<div class="col-md-12 box" id="box-1" > </div>
<div class="col-md-12 box" id="box-2" > </div>
<div class="col-md-12 box" id="box-3" > </div>
<div class="col-md-12 box" id="box-4" > </div>