Javascript Show/Hide Sidebar

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • metaphysics
    New Member
    • May 2007
    • 59

    #1

    Javascript Show/Hide Sidebar

    I was browsing the Mozilla Developer Center when I came across their drop down sidebar. (live preview: http://developer.mozilla.org/en/docs..._Documentation)

    I would like to use something similar if not exact to this; can anyone help me?
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    They're using a list (ul) for the contents and showing/hiding them by setting the style.display property to "block" and "none" respectively.

    Comment

    • metaphysics
      New Member
      • May 2007
      • 59

      #3
      Originally posted by acoder
      They're using a list (ul) for the contents and showing/hiding them by setting the style.display property to "block" and "none" respectively.
      I don't know anything about javascript... the part I was interested in was that when you hid the sidebar, the content shifted over. The rolldown effect was cool, but I'm mainly interested in how to do the content shift. Can you be more specific?

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        Originally posted by metaphysics
        I don't know anything about javascript... the part I was interested in was that when you hid the sidebar, the content shifted over. The rolldown effect was cool, but I'm mainly interested in how to do the content shift. Can you be more specific?
        When you set style.display to "block" which is the default state, the contents show. When you set it to "none", the contents are removed. So all you have to do is toggle between "block" and "none".

        For example:
        [HTML]<a href="#" onclick="showhi de('test'); return false;">Hide</a>
        <span id="test" style="display: block">Test</span>[/HTML] and the showhide function:[CODE=javascript]function showhide(id) {
        var elem = document.getEle mentById(id);
        if (elem.style.dis play=="none") elem.style.disp lay = "block";
        else elem.style.disp lay = "none";
        }[/CODE]

        Comment

        • metaphysics
          New Member
          • May 2007
          • 59

          #5
          Originally posted by acoder
          When you set style.display to "block" which is the default state, the contents show. When you set it to "none", the contents are removed. So all you have to do is toggle between "block" and "none".

          For example:
          [HTML]<a href="#" onclick="showhi de('test'); return false;">Hide</a>
          <span id="test" style="display: block">Test</span>[/HTML] and the showhide function:[CODE=javascript]function showhide(id) {
          var elem = document.getEle mentById(id);
          if (elem.style.dis play=="none") elem.style.disp lay = "block";
          else elem.style.disp lay = "none";
          }[/CODE]
          Thanks a bunch, I'll try it out.

          Comment

          Working...