Firefox offsetLeft

Discussion in 'Javascript' started by Paul Nash, Jun 9, 2006.

  1. Paul Nash

    Paul Nash Guest

    This is a dropdown menu script thats works ok in IE but is not positioning
    properly in Firefox. m.style.pixelLeft and Top are being set to the right
    values. But the menu, in a div block, is being displayed as though the
    pixelLeft and Top are being ignored.

    <script type='text/javascript' >
    var cm=null;
    document.onclick = new Function("show(null)")
    function getPos(el,sProp) {
    var iPos = 0
    while (el!=null) {
    iPos+=el["offset" + sProp]
    el = el.offsetParent
    }
    return iPos
    }

    function show(el,m) {
    if (m) {
    m.style.pixelLeft = getPos(el,"Left")
    m.style.pixelTop = getPos(el,"Top") + el.offsetHeight
    m.style.display='';
    }
    if ((m!=cm) && (cm)) cm.style.display='none'
    cm=m
    }
    </script>
    .. . .
    <a href='page?page=gifts' class='menulink'
    onmouseover='show(this,menu_gifts);' >
    Gifts
    </a>
    .. . .

    <!-- MENU BOX for gifts -->
    <div id='menu_gifts' class='submenu' style='display: none;' >

    <!-- start of imagebox -->
    <table cellspacing='0' cellpadding='0' border='0'>
    <tbody>
    .. . .

    Regards, Paul Nash
    Paul Nash, Jun 9, 2006
    #1
    1. Advertising

  2. Paul Nash

    Robert Guest

    Paul Nash wrote:
    > This is a dropdown menu script thats works ok in IE but is not positioning
    > properly in Firefox. m.style.pixelLeft and Top are being set to the right
    > values.


    pixelLeft and pixelTop are IE specific properties. Of course you can add
    these properties, but they don't have any meaning for Firefox.

    > function show(el,m) {
    > if (m) {
    > m.style.pixelLeft = getPos(el,"Left")
    > m.style.pixelTop = getPos(el,"Top") + el.offsetHeight


    Try this:
    m.style.left = getPos(el,"Left") + "px";
    m.style.top = (getPos(el,"Top") + el.offsetHeight) + "px";

    Robert.
    Robert, Jun 9, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Gary Coutts

    Firefox offsetLeft problem

    Gary Coutts, Mar 22, 2006, in forum: ASP .Net
    Replies:
    2
    Views:
    8,954
    Gary Coutts
    Mar 24, 2006
  2. Pieter Van Waeyenberge

    offsetLeft & Top differ for different element types?

    Pieter Van Waeyenberge, Feb 15, 2004, in forum: Javascript
    Replies:
    0
    Views:
    109
    Pieter Van Waeyenberge
    Feb 15, 2004
  3. Pieter Van Waeyenberge
    Replies:
    2
    Views:
    141
    Pieter Van Waeyenberge
    Feb 16, 2004
  4. Saqib Ali
    Replies:
    11
    Views:
    171
    Richard Cornford
    Feb 27, 2004
  5. Keith Thornhill

    offsetLeft/Top Bug in Firefox? (value is 8)

    Keith Thornhill, Aug 15, 2004, in forum: Javascript
    Replies:
    4
    Views:
    267
    Grant Wagner
    Aug 16, 2004
Loading...

Share This Page