Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Popup menu (like ipb)

  1. #1
    Join Date
    Dec 2006
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Popup menu (like ipb)

    Hi all!

    Has anyone some idea how can make a popup menu like in Invision power board in "Forum Option" or like at Vbulletin in "Tools" or "Search".

    So, I mean when click on button open menu and when click in second time to close (on button or out ... some where in page).

  2. #2
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <title>Hover</title>
    <style type="text/css">
    .dialog {
    position:absolute;
    padding:3px;
    border:1px solid gray;
    font:10pt arial;
    display:none;
    }
    </style>
    <script type="text/javascript">
    function show(cur,element) {
      var el = document.getElementById(element);
      if (el.style.display == "block") {
        el.style.display = "none";
        }
      else {
        el.style.left = cur.offsetLeft+"px";
        el.style.top = cur.offsetTop+cur.offsetHeight+"px";
        el.style.display = "block";
        }
      return false;
      }
    </script>
    </head>
    <body>
    <a href="#" onclick="return show(this,'dlg1');">Test</a>
    <div id="dlg1" class="dialog">
    Text to show.
    </div>
    </body>
    </html>
    - Mike

  3. #3
    Join Date
    Dec 2006
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    mburt thanx for replying me but there is a litle problem.
    Menu disapear if I click in "Test". I want to disapear menu if I click in page too.

  4. #4
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    Code:
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <title>Hover</title>
    <style type="text/css">
    .dialog {
    position:absolute;
    padding:3px;
    border:1px solid gray;
    font:10pt arial;
    display:none;
    }
    </style>
    <script type="text/javascript">
    function show(cur,element) {
      var el = document.getElementById(element);
      if (el.style.display == "block") {
        el.style.display = "none";
        }
      else {
        el.style.left = cur.offsetLeft+"px";
        el.style.top = cur.offsetTop+cur.offsetHeight+"px";
        el.style.display = "block";
        }
      return false;
      }
    </script>
    </head>
    <body>
    <a href="#" onclick="return show(this,'dlg1');" onblur="this.style.display='none';">Test</a>
    <div id="dlg1" class="dialog">
    Text to show.
    </div>
    </body>
    </html>
    - Mike

  5. #5
    Join Date
    Dec 2006
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Lol this disapear "Test" not menu on click somewhere in page.
    I dont know if have understand what I want...

  6. #6
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    Lol... Point taken.
    Replace the "this" with:
    Code:
    document.getElementById('dlg1')
    - Mike

  7. #7
    Join Date
    Dec 2006
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    not work again.

    and menu show on top of page not where I want (ex. in a cell table)

  8. #8
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    The only thing that I can really help out with in this matter is the disappearing link 'Test'. Simply go back to the original script that mburt has posted, then remove the onblur part from the link. That will stop the 'Test' link from disappearing and also get the menu to show up underneath the link.

    As for getting the menu to close when the user clicks outside of the div, no clue. I was playing around with it, but could not figure it out.

    Anyways, hope this helps.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  9. #9
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    Sorry, I posted the code really quickly, in a rush:
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <title>Hover</title>
    <style type="text/css">
    .dialog {
    position:absolute;
    padding:3px;
    border:1px solid gray;
    font:10pt arial;
    display:none;
    }
    </style>
    <script type="text/javascript">
    function show(cur,element) {
      var el = document.getElementById(element);
      el.style.left = cur.offsetLeft+"px";
      el.style.top = cur.offsetTop+cur.offsetHeight+"px";
      el.style.display = "block";
      document.onclick = function(e) {
      var obj = document.all ? event.srcElement : e.target;
        if (obj != el && obj != cur) {
          el.style.display = "none";
          }
        }
    }
    </script>
    </head>
    <body>
    <a href="#" onclick="show(this,'dlg1');">Test</a>
    <div id="dlg1" class="dialog">
    Text to show.
    </div>
    </body>
    </html>
    Should work, but I'm on my dad's laptop, and can't test in Firefox.
    - Mike

  10. #10
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    Tested and works like a charm. The only thing that I could see that could be better is this part:

    Code:
    <a href="#" onclick="show(this,'dlg1');">Test</a>
    Change it to:

    Code:
    <a href="#" onclick="show(this,'dlg1'); return false;">Test</a>
    Hope this helps.

    //EDIT: To see a test of this code, go to http://phphost.smackum.com/test2.html
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

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
  •