xecic,
<!DOCTYPE HTML>
<html>
<head>
<title>Untitled</title>
<meta charset="utf-8">
<style type="text/css">
body{
position: relative;
height: 700px;
}
hr.connection{
position: absolute;
width: 500px;
height: 2px;
background-color: #FF0000;
padding: 0;
margin: 0;
z-index: 2;
margin-top: 4px;
margin-left: 4px;
z-index: -1;
}
.one {
background-color: #FFD700;
position: absolute;
width: 8px;
height: 8px;
border-radius: 8px;
border: 4px solid #8B4513;
}
div.hot{
position: relative;
width: 500px;
height: 500px;
border: 1px dashed Gray;
margin: 20px auto;
}
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script>
(function($) {
$.fn.connectionItem = function(options) {
var defaults = {
to: $(window),
parent : "body"
};
var settings = $.extend({}, defaults, options);
return this.each(function() {
var from = $(this);
var x0, y0;
var x, y, x1, y1, r;
var to = $(settings.to);
var hr = $("<hr/>", {
"class": "connection",
css: {
position: "absolute"
}
}).appendTo(settings.parent);
hr.css("transform-origin", 0);
hr.css("-moz-transform-origin", 0);
hr.css("-webkit-transform-origin", 0);
hr.css("-o-transform-origin", 0);
function fn() {
var pos = from.position();
x0 = pos.left + from.width() / 2;
y0 = pos.top + from.height() / 2;
pos = to.position();
x1 = pos.left + to.width() / 2;
y1 = pos.top + to.height() / 2;
x = x1 - x0;
y = y1 - y0;
var w = Math.sqrt(x * x + y * y);
r = 360 - 180 / Math.PI * Math.atan2(y, x);
hr.css({
left: x0,
top: y0,
width: w
});
hr.css("transform", "rotate(-" + r + "deg)");
hr.css("-moz-transform", "rotate(-" + r + "deg)");
hr.css("-webkit-transform", "rotate(-" + r + "deg)");
hr.css("-o-transform", "rotate(-" + r + "deg)")
}
$(window).on({
resize: fn,
load: fn
})
})
}
})(jQuery);
$(function() {
function rand(a) {
return 5 + Math.floor(Math.random() * a)
}
var from ;
$.each(Array(3), function(indx, element) {
var div = $("<div>", {
css: {
top: rand(80) + "%",
left: rand(80) + "%"
},
"class": "one"
}).appendTo(".hot");
from && from.connectionItem({
to: div,
parent : ".hot"
});
from = div
})
from.connectionItem({
to: '.one',
parent : ".hot"
});
});
</script>
</head>
<body>
<div class="hot"></div>
</body>
</html>