SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Feb 2005
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    X Function Libray question

    Hi
    I've just started playing around with the x function library as supplied in the code for chapter 6 of Designing Without Tables Using CSS

    What I'm attempting to do is show (via an alert box) the left position of of a displayed graphic file.

    When I click on a button an alert windo pops up and is supposed to tell me the left position. The alert pops up ok but shows the value as 0 all the time.

    Could someone tell me what I'm doing wrong?

    Here's my code -

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
    <meta http-equiv="Content-Language" content="en-au">
    <title>Position test</title>
    <script src="resources/x.js" type="text/javascript"></script>
    <script type="text/javascript">
    function myfunction()
    {
    var xxx=xLeft("BugIcon"); // I've tried both 'bug' & 'BugIcon' here
    alert(xxx);
    //I've also tried this
    alert(xLeft("BugIcon"));
    }
    </script>
    <style>
    #bug {
    top: 50px;
    left: 50px;
    position: absolute;
    z-index: 1;
    }
    </style>
    </head>
    <body>
    <div id="bug">
    <div id="BugIcon"><img src="resources/bug.gif" border="0"></div>
    </div>
    <form>
    <input type="button"
    onclick="myfunction()"
    value="Call function">
    </form>
    </body>
    </html>

    TIA in advance
    Don

  2. #2
    SitePoint Addict dek's Avatar
    Join Date
    Oct 2004
    Location
    UK
    Posts
    352
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try xPageX/xOffsetLeft instead of xLeft

    Mike would likely be able to tell you more, but I tend to use xLeft purely for moving things - it doesn't seem to return a good result until I've already moved an element.

    xOffsetLeft returns the position of the item within its parent. xPageX gets the position within the whole page.

    Andy
    Only dead fish go with the flow

  3. #3
    SitePoint Member
    Join Date
    Feb 2005
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Andy
    xPageX works just fiine


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
  •