MyBB Community Forums

Full Version: Javascript Help
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I have this following code:
<script type="text/javascript">
function toggleLayer( whichLayer )
{
  var elem, vis;
  if( document.getElementById )
    elem = document.getElementById( whichLayer );
  else if( document.all )
      elem = document.all[whichLayer];
  else if( document.layers ) 
    elem = document.layers[whichLayer];
  vis = elem.style;
  // if the style.display value is blank we try to figure it out here
  if(vis.display==''&&elem.offsetWidth!=undefined&&elem.offsetHeight!=undefined)
    vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none';
  vis.display = (vis.display==''||vis.display=='block')?'none':'block';
}
</script>

It makes my sidebar disappear when a link is clicked, however, when, I my sidebar disappears, my forum is still the same width as it was with the sidebar there, leaving a lot of white space.
I wish to clear that white space by making the forum increase in width to (100%) when the sidebar is gone, so could I add another factor to the javascript?
So, other than making the display: none; turn into display: block;, can I also add width: 75%; to width: 100%; when clicked?
Something like IPB's over here:
http://forums.invisionpower.com/
One more thing, when the sidebar is there, it shows hide sidebar, when it's not, it still says hide sidebar.
Is there someway to make it say show sidebar afterwards? I have Yumi's PHP in Templates and Conditionals installed.
This is my code:
<a href="javascript:toggleLayer('f_h');" title="Hide Sidebar">
Hide Sidebar
</a>
I'd really appreciate it if you could help!
Looks like it is working to me. I click the x above the side bar and it disappears and the width of the main forum expands
Can i suggest you use Jquery? It would be easier, quicker and you could add some cool fade effects.
@skywalker
Really? It's working? Are you using a fluid site?

@_Tim
Ok, I'll give it a try, but I've already tried the sliding effect with jquery.
Try fade, it is usually pretty straight forward.