jQuery Animation How to - Move an Element in All Directions








Question

We would like to know how to move an Element in All Directions.

Answer


<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'
  src='http://code.jquery.com/jquery-1.4.2.js'></script>
<script type='text/javascript'>
$(window).load(function(){<!--  w  w w  .  j a v a2 s.c o  m-->
    $("#div").animate({left: '+=100', top: '+=100'}, 1000);
});
</script>
</head>
<body>
  <div id="div"
    style="width: 100px; height: 100px; border: solid 1px red; position: relative;">Test</div>
</body>
</html>

The code above is rendered as follows: