SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Member
    Join Date
    Jan 2005
    Location
    Berlin
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    xMenu1a getting wrong position due to nested div

    Hello,


    Here is a question for Mike Foster regarding xMenu1a (which is brilliant, thank you very much for sharing your cool toys). The main content in my page is continuously centered horizontally in the page by placing it all inside a div which has the margin property set to "0 auto". This has the result of breaking the positioning that xMenu1a gets from 'trg' -- if the page is really small the menus appear in approximately the right place, but if it is widened horizontally, they appear too far to the right, and the wider the page, the farther to the right. I am uploading a folder with examples of the relevant files so you can take a look at it. The triggers for the menus are transparent gifs called clear_1px.gif in case that isn't clear.

    Can you give me some help in getting the menus to turn up where expected?

    Thank you very much in advance,


    Alex
    Attached Files Attached Files

  2. #2
    I'll take mine raw silver trophy MikeFoster's Avatar
    Join Date
    Dec 2002
    Location
    Alabama, USA
    Posts
    2,560
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Alex, Welcome to the forums!

    Sorry, I haven't had a chance to look at your code. It may be later today or tonight before I get a chance. Thanks!

  3. #3
    SitePoint Member
    Join Date
    Jan 2005
    Location
    Berlin
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Mike,


    Glad to be here! No time pressure; you're doing me a favor by checking this stuff out.


    Cheers,


    Alex

  4. #4
    I'll take mine raw silver trophy MikeFoster's Avatar
    Join Date
    Dec 2002
    Location
    Alabama, USA
    Posts
    2,560
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Alex,

    In your HTML the menu elements are children of the 'container' element, which is relatively positioned, so the menu elements will be positioned relative to 'container', which has the margin. Here are 2 suggestions:

    1) Move the menu HTML elements outside of the 'container' element.

    or...

    2) Leave the HTML as it is, then when positioning a menu element subtract the container's left offset.
    To do this I made a few changes:

    Code:
      function onOpen()
      {
        if (!isOpen) {
          var x = xPageX(trg) - xPageX('container'); // mf
          xMoveTo(mnu, x, xPageY(trg)); // mf
          xShow(mnu);
          xSlideTo(mnu, x, xPageY(trg) + xHeight(trg), slideTime); // mf
          xAddEventListener(document, 'mousemove', onMousemove, false);
          isOpen = true;
        }
      }
      function onMousemove(ev)
      {
        var e = new xEvent(ev);
        if (!xHasPoint(mnu, e.pageX, e.pageY, -mouseMargin) &&
            !xHasPoint(trg, e.pageX, e.pageY, -mouseMargin))
        {
          xRemoveEventListener(document, 'mousemove', onMousemove, false);
          var x = xPageX(trg) - xPageX('container'); // mf
          xSlideTo(mnu, x, xPageY(trg), slideTime); // mf
          setTimeout("xHide('" + menuId + "')", slideTime);
          isOpen = false;
        }
      }
    btw, these are the only js files you need for that page:

    Code:
    <script type='text/javascript' src='./js/x_core.js'></script> 
    <script type='text/javascript' src='./js/x_event.js'></script> 
    <script type='text/javascript' src='./js/x_slide.js'></script>
    And you can delete this line:

    pg.onLoad();

    It's looking great!

  5. #5
    SitePoint Member
    Join Date
    Jan 2005
    Location
    Berlin
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Mike, that worked perfectly! Glad you like the layout -- thanks very much for taking the time.


    All the best,


    Alex

  6. #6
    I'll take mine raw silver trophy MikeFoster's Avatar
    Join Date
    Dec 2002
    Location
    Alabama, USA
    Posts
    2,560
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You're very welcome

    When the site goes live please let us know the url - this is a great example of utilizing xMenu1, I'd like to link to it.

  7. #7
    SitePoint Member
    Join Date
    Jan 2005
    Location
    Berlin
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Will do! I'd also like to link to cross-browser.com and credit you for the menu code on the site. I'll post when it's live in a week or so.


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
  •