Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-1.9.0.min.js"></script>
<meta charset=utf-8 />
<title>JS Bin</title>
  <style>
    html,body{
        height:auto;
        background:yellow;
        margin:14px;
        }
    #number1{
        background-color:orange;
        position:relative;
        top:0;
        left:0;
        width:100%;
        height:100%;
        }
    #number2{
        width:225px; 
        height:240px;
        background:black;
        padding:14px;
        color:orange;
        position:absolute;
        top:0;
        left:0;
        border:6px solid white;
        }
  </style>
</head>
<body>
  
  
  <div id="number1">
    <div id="number2">     xx 
    </div>
   </div>
  <script>
  $(function(){
    
    whatever();
    
    $(window).resize(function() {
      whatever();
    });
  });
  function whatever() {
    movebox();
    updatebox();
  }
    
  function movebox() {
    var offset = $('#number2').offset();
    $('#number2').css({
      left:(0 - offset.left),
      top:(0 - offset.top)
    });
  }
    
  function updatebox(){
    // demo nonsense to be ignored
    var offset = $('#number2').offset();
    $('#number2').text('Position: ' + offset.top + ' x ' + offset.left);
  }
    
    
  </script>
  
</body>
</html>
Output 300px

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
anonymouspro
0viewers