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 3 of 3
  1. #1
    New Coder bigtiger's Avatar
    Join Date
    Oct 2005
    Posts
    98
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question more 20 pixels width?

    hi,
    I'am newbie to javascript.
    there is a simple question that,
    any reasons a web page is width more 20
    pixels.
    I written a simple code that loop throught the
    element to calc the distance from left page to
    target element. when its run, it show me
    2 more span tag with each 10 pixels width.
    is that normal or not?

    thank you

    Eric,

  • #2
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Without seeing your code it could be a number of things but you say width, well it could be the scrollbar taking up those 20px but then you say it picks up two more spans? Show us your code.

  • #3
    New Coder bigtiger's Avatar
    Join Date
    Oct 2005
    Posts
    98
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question

    thanks _Aerospace_Eng_
    the code listed,

    <!-- html code -->
    <html>
    <body>
    <div id="level1" style="position:absolute;left:100;top:100;width;200;
    height:200">
    <div id="level2" style="position:absolute;left:100;top:100;width;100;
    height:100">
    </div>
    </div>
    <input type="button" value="Check it"
    onclick="return checkwidth(document.all.level2);" />
    </body>
    <html>

    // script code
    function checkwidth(link) {
    if(!link) {
    window.status = "parameters null";
    return;
    }

    var obj = new Object();
    obj.x = link.offsetLeft;
    obj.y = link.offsetTop;
    obj.width = link.style.posWidth;
    obj.height = link.style.posHeight;

    var parentEl = link.parentElement;
    while(parentEl) {
    var lastParent = parentEl;
    alert(parentEl.tagName + " / " + parentEl.offsetLeft);
    obj.x += parseInt(parentEl.offsetLeft);
    obj.y += parseInt(parentEl.offsetTop);
    parentEl = parentEl.parentElement;
    }
    window.status = lastParent.tagName;
    return false;
    }

    coz I'am newbie, many things dont know. if I'am wrong, please point out that.
    thanks a lot


  •  

    Posting Permissions

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