Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 18th, 2012  |  syntax: None  |  size: 0.77 KB  |  hits: 8  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. How do i make a div animate diagonally?
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <link href="style.css" rel="stylesheet"/>
  6. <script type="text/javascript" src="http://code.jquery.com/jquery-1.7.2.min.js"></script>
  7. </head>
  8. <body>
  9. <script type="text/javascript">
  10. $(document).ready(function(){
  11.  $("#box1 div").animate({left: '+=150', top: '+=150'}, 1000);​​​​​​​​​​​​​​​
  12. });
  13. </script>
  14. <div id="box1"></div>
  15. </body>
  16. </html>
  17.        
  18. #box{
  19.     position: absolute;
  20. }
  21.  
  22. $("#box1").animate({left: '+=150', top: '+=150'}, 1000);
  23.        
  24. $("div#box1")   //correct
  25.        
  26. $("#box1 div")  //incorrect
  27.        
  28. <div id="box1" style="position:absolute;">s</div>
  29.        
  30. $("#box1 div").animate({left: '+=150', top: '+=150'}, 1000);
  31.        
  32. $("#box1").animate({left: '+=150', top: '+=150'}, 1000);