JSFiddle - React, Tailwind, and code Playground
by Zevan
JavaScript
var container = new Element(0, 0, 500, 400, "#999");
var padding = 10;
var elements = [];
var x = 0, y = 0, previous;
for (var i = 0; i<10; i++){
var e;
if (!previous){
e = new Element(x, y, Math.random() * 100 + 10, Math.random()*100 + 10);
}else {
e = new Element
}
previous = e;
elements[i] = e;
}
function Element(x, y, w, h, col){
if (!col) col = "red";
var div = document.createElement("div");
with(div.style){
position = "absolute";
border = "1px solid black";
backgroundColor = col;
width = w + "px";
height = h + "px";
left = x + "px";
top = y + "px";
}
document.body.appendChild(div);
this.getX = function(){
return x;
}
this.getY = function(){
return y;
}
this.setX = function(x){
console.log("hi");
div.style.left = x + "px";
}
this.sety = function(y){
div.style.top = y + "px";
}
}