Click to See Complete Forum and Search --> : How do i convert pixcel coordinates to table coordinates
Adi5402
12-23-2003, 07:55 AM
My table is positioned relative and iv got an absolute ball floatng over it i need the ball to interact with the table so i need some hting which can tell me exactly which table row and colum the ball is over can some one help
I think you can use some values to find the absolute position and dimentions of an element (table, row, cell...) with a certain id
document.getElementById(id).offsetLeft
document.getElementById(id).offsetTop
document.getElementById(id).offsetWidth
document.getElementById(id).offsetHeight
Adi5402
12-23-2003, 08:10 AM
Ya i guess it might work but will that help me get value of i because im going to use a if statement with tdarray[i] to check the table cells.
that use getElementsByTagName
document.getElementsByTagName('td')[i].offsetLeft
and so on....
Adi5402
12-30-2003, 07:06 AM
iv got the following ccode so far but it ant detecting the right code ill upload the files and post alink within the hour
objball = document.getElementById("ball");
var ox =objball.offsetLeft;
var oy =objball.offsetTop;
if (ox%20==0)
{
rn = (ox - 20)/20;
}
if(oy%5 == 0)
{
cn = ((oy-5)/5)-5;
i = ((rn)*21)+(cn+1);
//alert(i);
}
if (obj2[(rn*21)+cn].className=='brick3' )
{
obj2[(rn)*21+(cn)].setAttribute('id', 'brick2' );
}
//this detects the bricks but some ones on the side iv got 21 colums and 50 rows