View Full Version : Transform coordinates (x,y) in pixels
Alvorada
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?
Thanks!
djr33
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.
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;
vwphillips
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';
Aha - good point. Maybe parseInt() is also essential? I wouldn't know that much about this though.
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.