Jquery Slideup and Slidedown

The jQuery slideDown() method is used to slide down an element.

The jQuery slideUp() method is used to slide up an element.

These two methods are perfect for showing and hiding content in a non-jarring manner. The slideDown() method shows content by sliding open a given element; the slideUp() method, on the other hand, hides content by sliding closed a given element. These are very basic methods.

Following example shows, how can we display a child menu on hover of elements with slideUp() and slideDown() methods.

Here is the HTML code.

<ul>
    <li><a href="index.php" class="current_link">THE LATEST</a></li>
    <li><a href="community.php" >COMMUNITY</a>
        <ul>
            <li><a href="chat.php" >Video Chat</a></li>
        </ul>
    </li>
    <li><a href="business.php" >BUSINESS</a>
        <ul>
            <li><a href="market_price.php">Market Rates &amp; Trading</a></li>
        </ul>
    </li>
    <li><a href="entertainment.php" >ENTERTAINMENT</a></li>
    <li class = "top_menu"><a href="#" >LIFESTYLE</a>
        <ul class = "sub_menu">
            <li><a href="top_eats.php">TOP EATS</a></li>
            <li><a href="night_life.php">NIGHT LIFE</a></li>
            <li><a href="special_events.php">SPECIAL EVENTS</a></li>
            <li><a href="health_and_wellbeing.php">HEALTH &amp; WELL BEING</a></li>
            <li><a href="lgbt.php">LGBT</a></li>
        </ul>
    </li>
    <li><a href="sports.php" >SPORTS</a></li>
    <li><a href="classified.php" >CLASSIFIED</a></li>
    <li class = "top_menu">
        <a href="#" style="position:relative;" >VIDEOS</a>
        <ul class = "sub_menu">
            <li><a href="the_latest.php">Live Shows</a></li>
            <li><a href="videos.php">Video Archive</a></li>
        </ul>
    </li>
</ul>


Script that does the effects.

$(".top_menu").children("ul").hide();
$(".top_menu").hover(function() {
    $(this).children(".sub_menu").slideDown(1000);
}, function() {
    $(this).children(".sub_menu").slideUp(1000);
});


Some css to keep the lists in proper way.

ul{marign:5px;}
ul li{margin:2px}
ul li ul{margin-left:30px}
.top_menu a{color:#ff0000;font-weight:bold;}



Comments

Popular posts from this blog

Gradient Border Colors with CSS

10 Useful Libraries and Resources for Responsive Web Design

The Simplest Way To Center Elements Vertically And Horizontally