JQuery Sliding Effect

In this blog, I’m explaining the sliding effect in jquery and how to use it.

JQuery provides slide methods to slide elements of your document. Jquery provide three methods to show and hide the elements in slide behavior:

1.   SlideDown(speed, callback) :- It increases the height of the element, from hidden to visible.

2.  SlideUp(speed, callback) :- It decreases the height of the element, from visible to hidden.

3.  SlideToggle(speed, callback) :- This method toggles between SildeUp() and SlideDown() for selected elements.

All three methods have 'Speed' and 'callback' parameters. The Speed parameter can have the following values:

·     slow

·     normal

·     fast

·     milliseconds, e.g., 10, 50, 100, etc.

The callback parameter is the name of a function that executes after the function completes.


In this example, we create a collapse box which will be visible when the page loads and when we click on “Click here”, it slide up smoothly and again click on “Click here” it will slide down smoothly and if we click on “Close” –  the collapse box will slide up rapidly.

First create an empty asp.net application and add a webform to it.

And write the below code in it:

<%@ Page Language='C#' AutoEventWireup='true' CodeBehind='CollapseBox.aspx.cs' Inherits='JqueryApp.CollapseBox' %>
<!DOCTYPE html>
<html xmlns='http://www.w3.org/1999/xhtml'>
<head runat='server'>
    <script src='SCRIPT/jquery-1.11.0.min.js'></script>
    <script type='text/javascript'>
        $(document).ready(function () {
            $('#CollapseHeader').click(function () {
            $('#Close').click(function () {
    <form id='form1' runat='server'>
        <div style='width: 400px; border: 2px; border-style: solid; border-color: black;'>
            <div style='background-color: brown; color: white;'>
                Collapse Box(<a href='#' id='CollapseHeader' style='color: white;'>Click Here</a>)
            <div id='contentArea'>
                <div align='right'>
                    <a id='Close'
                        href='#' style='font-size: 10px;'>Close</a>
                Content of Collapse Box<br />
                This collapse box will slide up when you click on 'Click Here'


Now run the application

When you click on the “Click Here” – the collapse box will slide up like this:

And when you again click on “Click Here” – the collapse box will slide down like this:

And when you click on “Close” – the collapse will slide up rapidly like this:

Last updated:9/18/2014 1:24:23 PM


Leave Comment