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

Untitled

By: a guest on Apr 26th, 2012  |  syntax: None  |  size: 1.42 KB  |  hits: 13  |  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. Margins relative to current Div
  2. <html>
  3. <head>
  4.  
  5. <script src="javascript/jQuery-1.7.1.min.js" type="text/javascript"></script>
  6.  
  7. <style type="text/css">
  8.  
  9. #maincontent{
  10. padding-bottom: 3em;
  11. width: auto;
  12. background:#fff;
  13. text-align: left;
  14. margin-left: 10%;
  15. margin-right: 10%;
  16. margin-top: 60px;
  17. }
  18.  
  19. #animateBox
  20. {
  21. height: 100px;
  22. width: 100px;
  23. background: red;
  24. position: absolute;
  25. }
  26.  
  27. #moveLeft
  28. {
  29. display: none;
  30. }
  31.  
  32. #moveRight
  33. {
  34. display: inline;
  35. }
  36.  
  37. </style>
  38.  
  39. <script type="text/javascript">
  40. $(document).ready(function() {
  41.     $('#moveRight').click(function() {
  42.         $("#animateBox").animate(
  43.             {"left": "+=200px"},"normal");
  44.             $('#moveRight').css('display', 'none');
  45.             $('#moveLeft').css('display', 'inline');
  46.     });
  47.  
  48.     $("#moveLeft").click(function() {
  49.         $("#animateBox").animate(
  50.             {"left": "-=200px"},
  51.             "normal");
  52.             $('#moveLeft').css('display', 'none');
  53.             $('#moveRight').css('display', 'inline');
  54.  
  55.     });
  56. });
  57.  
  58. </script>
  59.  
  60. </head>
  61. <body>
  62.  
  63. <div id="maincontent">
  64.  
  65. <div id="animateBox"></div>
  66.  
  67. <br />
  68. <br />
  69. <br />
  70. <br />
  71. <br />
  72.  
  73. <input type="button" id="moveRight" Value="Move Right" style="width: 100px">
  74. <input type="button" id="moveLeft" Value="Move Left" style="width: 100px">
  75.  
  76. </div>
  77. </body>
  78.        
  79. #maincontent{
  80. padding-bottom: 3em;
  81. width: auto;
  82. background:#fff;
  83. text-align: left;
  84. margin-left: 10%;
  85. margin-right: 10%;
  86. margin-top: 60px;
  87. position:relative /*Add this*/
  88. }