...

View Full Version : coordinate plane in javascript



cwl157
10-28-2003, 02:51 AM
I want to make a coordinate plane in javascript and then have pictures at certain coordinates and then refer to each picture by its coordinate point. I have no idea how to do this. Can someone help me. Thanks

Kor
10-28-2003, 07:39 AM
use getElementById method (and all[id] &layers[id] if you want it to work cross-browser IE4 & NS4) to create an object and styles-on-fly to setup its X and Y position (style.left and style.top).



<html>
<head>
<script>
function objSetup(){
ztheid = new layerSetup('theid',100,200);
}

function layerSetup(id,left,top){
if(document.getElementById){
this.obj = document.getElementById(id).style;
this.obj.left = left;
this.obj.top = top;
return this.obj;
}
if(document.all){
this.obj = document.all[id].style;
this.obj.left = left;
this.obj.top = top;
return this.obj;
}
if(document.layers){
this.obj = document.layers[id];
this.obj.left = left;
this.obj.top = top;
return this.obj;
}
}

</script>
</head>
<body onload = "objSetup()">
<div id="theid" style="position:absolute"><img src="yourimage.jpg"></div>
</html>


Now you have a relation between the coordinates

xpoz = parseInt(ztheid.left);
ypoz = parseInt(ztheid.top);

and the id of the object

id = 'theid';

cwl157
10-28-2003, 10:01 PM
Thanks for the code. I have another question. I figured out how to put up the pictures but no matter what values i type in for the coordinates it only goes down in one column. How do i make it go down a second column next to the first?

Kor
10-29-2003, 08:32 AM
I don't see how that is possible... Maybe you forgot to give a position in style, I mean, you have to specify somewere , say in style= or in class, or in style-on-flay the tipe of position, position:absolute, otherwise any positioning is without any effect.

(of course, you may use position:relative either... Anyway, you must specify the type)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum