Jump to content

Collapsing menu


magicadmin

Recommended Posts

Right i have this working sort of.. but when i refresh the page it opens the menu then it closes it again once its been closed plus i would like it to have all of it closed when the page is first loaded???

    <script type="text/javascript">    function init()    {        var cookie = getCookie('collapse_obj');        if(cookie)        {            var values = cookie.split(',');            for(var i = 0; i < values.length; i++)            {                var itm = getItem(values[i]);                if(itm)                    itm.style.display = 'none';            }        }    }    function makeCookie(name, value)    {        var cookie = name + '=' + escape(value) + ';';        document.cookie = cookie;    }    function getCookie(name)    {        if(document.cookie == '')            return false;        var firstPos;        var lastPos;        var cookie = document.cookie;        firstPos = cookie.indexOf(name);        if(firstPos != -1)        {            firstPos += name.length + 1;            lastPos = cookie.indexOf(';', firstPos);            if(lastPos == -1)                lastPos = cookie.length;            return unescape(cookie.substring(firstPos, lastPos));        }        else            return false;    }    function getItem(id)    {        var itm = false;        if(document.getElementById)            itm = document.getElementById(id);        else if(document.all)            itm = document.all[id];        else if(document.layers)            itm = document.layers[id];        return itm;    }    function toggleItem(id)    {        itm = getItem(id);        if(!itm)            return false;        if(itm.style.display == 'none')            itm.style.display = '';        else            itm.style.display = 'none';        ////////////////////        cookie = getCookie('collapse_obj');        values = new Array();        newval = new Array();        add    = 1;        if(cookie)        {            values = cookie.split(',');            for(var i = 0; i < values.length; i++)            {                if(values[i] == id)                    add = 0;                else                    newval[newval.length] = values[i];            }        }        if(add)            newval[newval.length] = id;        makeCookie('collapse_obj', newval.join(','));        return false;    }    </script><body onload="init()"><div id="nav"> tables here</div><a href="#" onclick="java script:toggleItem('nav')">Show/hide Navgation</a>

also i want to use 2 different images one for when its open and one for when its closed

<a href="#" onclick="java script:toggleItem('main')"><img src="./images/up.gif" border="0"></a>

<a href="#" onclick="java script:toggleItem('main')"><img src="./images/down.gif" border="0"></a>

How do i get this to check if the window is up or down and the display the right one ???And anther thought... how can i have it so only one menu is open at one time... IE when one is opened the other closes????Thanks

Link to comment
Share on other sites

Right i have this working sort of.. but when i refresh the page it opens the menu then it closes it again once its been closed plus i would like it to have all of it closed when the page is first loaded???
<div id="nav" style="display:none">That will ensure the menu is always disabled when the page is first viewed or refreshed.
also i want to use 2 different images one for when its open and one for when its closed
I have added this, just change the image using the function that changes the display
How do i get this to check if the window is up or down and the display the right one ???
The function takes care of that, if its not displayed show it, otherwise hide it.
And anther thought... how can i have it so only one menu is open at one time... IE when one is opened the other closes????
Create a function that hides all the menus before showing the one clicked. like: onclick="java script:hideAll();toggleItem('nav')"
<script type="text/javascript">   function toggleItem(id)   {     var x=document.getElementById(id);     var y=document.getElementById('pic');               if(x.style.display == 'none'){       x.style.display = 'block';       y.src="http://scott100.atspace.com/on.GIF";       }                  else{       x.style.display = 'none';       y.src="http://scott100.atspace.com/off1.GIF";       }   }   </script><body><div id="nav" style="display:none">tables here</div><a href="#" onclick="java script:toggleItem('nav')"><img id="pic" src="http://scott100.atspace.com/off1.GIF" /></a>

I have weeded the code right down, it was using cookies and all sorts, this is the bare minimum to make this run. :)

Link to comment
Share on other sites

<div id="nav" style="display:none">That will ensure the menu is always disabled when the page is first viewed or refreshed.
I need it to remmember what the last menu that was used on page refresh.
Create a function that hides all the menus before showing the one clicked. like:onclick="java script:hideAll();toggleItem('nav')"
I would not know where to begin to do that... im so new to javascript.Thanks
Link to comment
Share on other sites

I would not know where to begin to do that... im so new to javascript.
If you look here you will see an example of how this can be done.http://w3schools.invisionzone.com/index.ph...indpost&p=16948You could use a loop to cut down the lines of code, it's up to you really. :)
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...