+ 2
how to tell an element’s position in JS
so for a game i need to know an element’s position in javascript. how is this done?
2 Respostas
+ 10
privrax.
get that element into a variable like
var a = document.getElementById("id");
var top = a.offsetTop; //for vertical position
var left = a.offsetLeft; //for horizontal.
Store each of them in a variable i stored them in top and left you can choose yours.
+ 2
if your element is set with css display:fixed or display:absolute, you could check your element #obj position by
var element = document.getElementById("obj");
x = parseInt(element.style.x, 10);
y = parseInt(element.style.y, 10);