Results 1 to 3 of 3

Thread: [DHTML] Collapsable Div with limit

  1. #1
    Join Date
    Jun 2007
    Posts
    543
    Thanks
    3
    Thanked 78 Times in 78 Posts
    Blog Entries
    1

    Default [DHTML] Collapsable Div with limit

    Edit: There is a better version I have just made that is simpler then this here

    1) CODE TITLE: Collapsable Div with limit

    2) AUTHOR NAME/NOTES: Master_script_maker

    3) DESCRIPTION:
    A script that expands/collapses divs with a limit of how many can be opened. If someone tries to open more then the limit, the first one opened will be collapsed.
    To open/close a div with a link uses this:
    <a href="#" onClick="ReverseContentDisplay(Div id)" ></a>
    or with a button:
    <input type="button" value="" onClick="ReverseContentDisplay(Div id)" />



    4) URL TO CODE: http://masterproject.freehostia.com/div/

    Here is the code for it:
    Code:
    <script type="text/Javascript"> 
    
    var num=5;   //number of div's that are allowed open at a time
    var previousD = new Array();
    var last;
    function HideContent(d) {
      document.getElementById(d).style.display = "none";
    }
    function ShowContent(d) {
      document.getElementById(d).style.display = "";
    }
    function ReverseContentDisplay(d) {
      var i=num;
      if(document.getElementById(d).style.display == "none") {
        if(previousD[0] != null) {
          if(num != 1 && last != "hide") { 
            while(i>0) {
              var j=i-1;
              previousD[i] = previousD[j];
              i=i-1;  
            }
            if(previousD[num] != null) {
             HideContent(previousD[num])
            }
          } else {
            last="";
            if(num==1) {HideContent(previousD[0]);}
          }
        }
        ShowContent(d); 
        previousD[0] = d; 
      }else {
        last="hide";
        HideContent(d);
      }
    }
    </script>
    Last edited by Master_script_maker; 12-31-2007 at 10:52 PM. Reason: forgot to add the script code
    [Jasme Library (Javascript Motion Effects)] My Site
    /\/\@§†ê® §©®¡þ† /\/\@|{ê®
    There are 10 kinds of people in the world, those that understand binary and those that don't.

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    I like that a lot. Simple yet useful.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  3. #3
    Join Date
    Jun 2007
    Posts
    543
    Thanks
    3
    Thanked 78 Times in 78 Posts
    Blog Entries
    1

    Default

    thanks, i tried to have a good compromize of functionality and simplicity
    Last edited by Master_script_maker; 12-26-2007 at 03:19 AM.
    [Jasme Library (Javascript Motion Effects)] My Site
    /\/\@§†ê® §©®¡þ† /\/\@|{ê®
    There are 10 kinds of people in the world, those that understand binary and those that don't.

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
  •