jQuery Animation How to - Smoothly animate a div to a specific location








Question

We would like to know how to smoothly animate a div to a specific location.

Answer


<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'
  src='http://code.jquery.com/jquery-1.8.3.js'></script>
<style type='text/css'>
#navbuttons {<!--from w ww .  j  a  v  a 2  s  .  c  om-->
  width: 100px;
  height: 100px;
  border: 1px solid #000;
  position: relative;
}
</style>
<script type='text/javascript'>
$(window).load(function(){
    $('#navbuttons').animate({
        top: '+=50px'
    }, 'slow');
});
</script>
</head>
<body>
  <div id="navbuttons"></div>
</body>
</html>

The code above is rendered as follows: