This is what I'm trying to do :
- function : Create a div with random top and left value,
- function : get the css value of this object (I'm there) and move this div :
I can't get the css value. it's return :
TypeError: undefined is not an object (evaluating 'elem1.style.top')
there is the javascript file :
var r = 50;
var rc = r /2;
var q = 0.2;
var wq = window.innerWidth/q;
function getRandomIntInclusive(min, max)
{
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min +1)) + min;
}
function getPosition()
{
var elem1 = document.getElementsByClassName('circle');
var value = elem1.style.top;
alert(value);
}
function createObject(wq,r,rc)
{
var square = document.createElement('div');
square.className = 'square';
square.style.width = "" + r + "px";
square.style.height = "" + r + "px";
var circle = document.createElement('div');
circle.className = 'circle';
circle.style.width = "" + rc + "px";
circle.style.height = "" + rc + "px";
circle.style.top = "" + getRandomIntInclusive(0, rc) + "px";
circle.style.left = "" + getRandomIntInclusive(0,rc) + "px";
square.appendChild(circle);
document.body.appendChild(square);
getPosition()
}
createObject(wq,r,rc);
Answer : - send the div I've created to the getPosition(circle) function - write the whole animation process etc.. and apply new random values.