<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
Keyboard Shortcuts
Shortcut | Action |
---|---|
ctrl + [num] | Toggle nth panel |
ctrl + 0 | Close focused panel |
ctrl + enter | Re-render output. If console visible: run JS in console |
Ctrl + l | Clear the console |
ctrl + / | Toggle comment on selected lines |
ctrl + ] | Indents selected lines |
ctrl + [ | Unindents selected lines |
tab | Code complete & Emmet expand |
ctrl + shift + L | Beautify code in active panel |
ctrl + s | Save & lock current Bin from further changes |
ctrl + shift + s | Open the share options |
ctrl + y | Archive Bin |
Complete list of JS Bin shortcuts |
JS Bin URLs
URL | Action |
---|---|
/ | Show the full rendered output. This content will update in real time as it's updated from the /edit url. |
/edit | Edit the current bin |
/watch | Follow a Code Casting session |
/embed | Create an embeddable version of the bin |
/latest | Load the very latest bin (/latest goes in place of the revision) |
/[username]/last | View the last edited bin for this user |
/[username]/last/edit | Edit the last edited bin for this user |
/[username]/last/watch | Follow the Code Casting session for the latest bin for this user |
/quiet | Remove analytics and edit button from rendered output |
.js | Load only the JavaScript for a bin |
.css | Load only the CSS for a bin |
Except for username prefixed urls, the url may start with http://jsbin.com/abc and the url fragments can be added to the url to view it differently. |