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 to the CF scene
    Join Date
    Jun 2007
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    windows coordinates mouseover

    I have a page which contain small images
    I want to get the windows coordinates for every small image
    IS this Possible in php/javascript

    Please send the example code if any.

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    PHP is not capable of handling mouseover events - it is preprocessed.
    Javascript is capable of recording position x and y for any html element.
    Examples... not sure if I can help you with that as my js is quite rusty, but I'll give it a shot:
    Code:
    <script type="text/javascript">
      var images = document.getElementsByTagName("image");
      var imageLocs = new Array();
      for (var i = 0; i < images.length(); i++)
      {
        imageLocs[i] = new Array(images[i].offsetX, images[i].offsetY);
      }
    </script>
    Ok... didn't test that out and honestly I don't think it will work. Lol, not even certain if the javascript syntax is correct on that one :P
    Unfortunatly, if I remember correctly, offset* retrieves the offset relative to a specified element. This element changes from browser to browser.
    Anyway, post it up in the js forum, surely someone can help you there!
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #3
    Senior Coder
    Join Date
    Aug 2002
    Location
    UK
    Posts
    2,789
    Thanks
    2
    Thanked 14 Times in 14 Posts
    Give this a try

    Code:
    <script type="text/javascript">
    
    onload=function test(){
      var images = document.getElementsByTagName("img");
      var imageLocs = new Array();
    
      for(var i = 0; i < images.length; i++){
      imageLocs[i] = new Array(images[i].offsetLeft, images[i].offsetTop);
      }
    
      alert(imageLocs)
    }  
    </script>
    This is on the premise that the images are in the natural flow of the document.
    If they are in a table or nested in positioned divs additional code will be required
    Last edited by Mr J; 06-09-2007 at 11:21 PM.
    The silent one.

    The most dangerous thing in the world is an idea.
    The most dangerous person in the world is the one with an idea.

  • #4
    Regular Coder Actinia's Avatar
    Join Date
    Feb 2007
    Location
    Essex, UK
    Posts
    250
    Thanks
    1
    Thanked 23 Times in 22 Posts
    Try the FindPos scripts by Peter-Paul Koch at:

    http://www.quirksmode.org/js/findpos.html

    and its update (to work with Safari) by Alex Tingle at:

    http://blog.firetree.net/2005/07/04/javascript-find-position


  •  

    Posting Permissions

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