View Full Version : Transform coordinates (x,y) in pixels

04-13-2010, 07:33 PM
Hey everybody!
Im studying javascript, and I tried to make a script for a image follow the cursor. The script calculate the coordinate of the cursor, but I cant put a coordinate in a css (style.left = coordinate_x)

What can I do?


04-14-2010, 02:18 AM
Either give us a link to your page or post the code here. It's too hard to guess what you are doing.

04-14-2010, 02:23 AM
Djr33 - he wants to make an image follow a cursor.

I hope you're using client(X, Y) and page(X, Y) including additional things. Anyways - just change the css within the Javascript:

document.getElementById('element').style.position = "absolute";
document.getElementById('element').style.left = posX;
document.getElementById('element').style.top = posY;

04-14-2010, 12:08 PM
document.getElementById('element').style.position = "absolute";
document.getElementById('element').style.left = posX+'px';
document.getElementById('element').style.top = posY+'px';

04-15-2010, 12:42 AM
Aha - good point. Maybe parseInt() is also essential? I wouldn't know that much about this though.