Ades Design - High Quality Website Templates, Free Website Templates, Tutorials: Photoshop, Dreamweaver, Flash, CSS and PHP


Hiding div layers after 5 seconds (specified time - x seconds)
Home » Tutorials » CSS


Many things can be done with layers, one of the most useful thing being the navigational drop down menus. Only problem with many HTML editors including Dreamweaver at the moment is that they do not provide an option to close or hide the layers after a specified time. So most of the time you need to hide it yourself by placing behaviors on other links or images, that way when you mouse over on certain images or links it will automatically hide the layers. However there is one shortcoming with this method, if the user does not mouse over on these particular images or links with behaviours your layer will stay visible.

This tutorial will teach you how to hide layers by themselves after let's say 5 seconds.

Before we proceed with the tutorial please have a look at the final outcome of the tutorial here.

Create a new page and call it hide_div.html. Create a link and a layer in the same page, rename your layer to Menu1. Now add a behaviour to your link, so that when you mouse over it will show the layer Menu1. If you do not know how to create layers then please read this tutorial first: Working with Layers.

By the way put # for the link url, otherwise you won't be able to add behaviors to the link unless of course it is actually linked to other page or url, but here we do not want to link it to other page we just want to show our Layer when it is mouse overed therefore putting # in the link url would solve this problem of linking to other page. Your link code should look like this:

<a href="#">Link1</a>

Now put this code in the Head section of your page, anywhere between <head> </head> tags.

<SCRIPT language="JavaScript">
<!--
function HideMenus()
{
setTimeout("HideOpenMenus()",5000);
}
function HideOpenMenus()
{
Menu1.style.visibility = 'hidden';
}
//-->
</SCRIPT>

Now go to the link that you added behavior previously. View it in Code View. You should see a code something similar to this:

<a href="#" onMouseOver="MM_showHideLayers('Layer1','','show')">Link 1 </a>

In your link code after ,'show')" and before > closing tag add onMouseOut="HideMenus();"

After adding the tag your code should look like below:

<a href="#" onMouseOver="MM_showHideLayers('Layer2','','show')" onMouseOut="HideMenus();">Link 1 </a>

Now hit the preview button in your Dreamweaver or HTML Editor and check how your page looks and if your link is functioning properly. After you mouse over on your link the layer should close after 5 seconds.

Let's go through the code and understand what it does.

 

Adding onMouseOut function to your link calls the HideMenu() function in the head section:

<a href="#" onMouseOver="MM_showHideLayers('Layer2','','show')" onMouseOut="HideMenus();">Link 1 </a>

Similarly HideMenu() function waits 5 seconds and calls HideOpenMenus() function:

<SCRIPT language="JavaScript">
<!--
function HideMenus()
{
setTimeout("HideOpenMenus()",5000);
}

function HideOpenMenus()
{
Menu1.style.visibility = 'hidden';
}
//-->
</SCRIPT>

And HideOpenMenus() function closes the Menu1 layer that you have created:

<SCRIPT language="JavaScript">
<!--
function HideMenus()
{
setTimeout("HideOpenMenus()",5000);
}
function HideOpenMenus()
{
Menu1.style.visibility = 'hidden';
}

//-->
</SCRIPT>

That's basically all.

If you want to hide the layer after 10 seconds specify the time as 10000, you can also close multiple layers at once by adding another line to the code like this:

Menu1.style.visibility = 'hidden';
Menu2.style.visibility = 'hidden';
Menu3.style.visibility = 'hidden';
Products.style.visibility = 'hidden';
AnyOtherName.style.visibility = 'hidden';

Related CSS Tutorials
  Hiding DIV layers after 5 seconds New
Learn how to hide all the div layers automatically after a specified time.
  Creating and linking external CSS files
Learn how to create and attach external CSS file to a page.
  Having different link colors on one page
Learn how to have more than one link color for the page.
  Fixed Image Background for the page
Learn how to make centered background that stays even when you scroll the page.

Color Picker for your AdSense job more info
 
I hope it was useful! Let me know if you have any questions.



Web2.0 Bookmarks - Social bookmarking is good, but old skool way of hand-picking sites is better!
That's what we do best, collecting the coolest WEB2.0 sites. click here

 


Advertise | AdesBlog New | Free Templates | Premium Templates | Products | Services | Portfolio | Contact

2002 - 2007 Ades Design. All Rights Reserved. http://www.adesdesign.net

 









Custom Logo Design Services by Logo Design Team for $149 Only
Software Development Company 
Search Engine Optimization by Design
 
Advertise Here