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.1.min.js"></script>
  
  <script src="//code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
  <meta charset="utf-8">
  <title>JS Bin</title>
</head>
<body><div id="degree"></div>
  <div id="line"></div>
  <div class='box' id='box2'  style='left:0px;top:0px;'>
  </div>
  
  
  
  
  <div class='box' id='box1'  style='left:200px;top:200px;'>
  </div>
</body>
</html>
 
function g()
{
 
var x1 = $("#box1").offset().left  ;
                    var x2 = $("#box2").offset().left ;
                    var y1 = $("#box1").offset().top  ;
                    var y2 = $("#box2").offset().top ;
                    var hypotenuse = Math.sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));
                    var angle = Math.atan2((y1-y2), (x1-x2)) *  (180/Math.PI);
                    if(angle >= 90 && angle < 180){
                        y1 = y1 - (y1-y2);
                    }
                    if(angle > 0 && angle < 90){
                        x1 = x1 - (x1-x2);
                        y1 = y1 - (y1-y2);
                    }
                    if(angle <= 0 && angle > -90){
                        x1 = x1 - (x1-x2);
                    }
                    
$("#line") .width(hypotenuse)
    .css('-webkit-transform', 'rotate(' + angle  + 'deg)')
    .css('-webkit-transform-origin','top left')
    .css('top',y2+8)
    .css('left',x2+10);
                         
                    
                    
                    //$("#degree").html(angle);
}
 $(function() {
   $( ".box" ).draggable(  {drag: function() {    g();   }});
  
 });
g();
Output

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

Dismiss x
public
Bin info
anonymouspro
0viewers