SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    Who turned the lights out !! Mandes's Avatar
    Join Date
    May 2005
    Location
    S.W. France
    Posts
    2,496
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Finding DIV offset

    Hi All

    Im hitting my head against the wall on what should be a simple JS application.

    I have various pages on a website that are structured with CSS positioned divs.

    I have a div that contains a bar that I want users to be able to drag up and down with the mouse. this can be be done by dynamically changing the CSS width of the div relative to the mouse position over it. Getting the mouse position isnt a problem but I'm having real bother getting the xoffset of the div position that allows me to work out how far into the div the mouse is.

    The script I'm trying to use is

    Code:
    function findPosX(obj)
      {
        var curleft = 0;
        if(obj.offsetParent)
            while(1) 
            {
              curleft += obj.offsetLeft;
              if(!obj.offsetParent)
                break;
              obj = obj.offsetParent;
            }
        else if(obj.x)
            curleft += obj.x;
        return curleft;
      }
    But I'm not getting anywhere, anyone see where I could be going wrong ??
    A Little Knowledge Is A Very Dangerous Thing.......
    That Makes Me A Lethal Weapon !!!!!!!!

    Contract PHP Programming

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,729
    Mentioned
    104 Post(s)
    Tagged
    4 Thread(s)
    Can you please provide some sample HTML, CSS and JavaScript prototype that demonstrates the issue? That will make it a lot easier to find a solution that's going to work for you.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


Bookmarks

Posting Permissions

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