Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Jun 2003
    Posts
    92
    Thanks
    0
    Thanked 0 Times in 0 Posts

    coordinate plane in javascript

    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

  • #2
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    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).

    PHP Code:
    <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';
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #3
    New Coder
    Join Date
    Jun 2003
    Posts
    92
    Thanks
    0
    Thanked 0 Times in 0 Posts

    thanks and i have another question

    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?

  • #4
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    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)
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •