Home > DeveloperSection > Blogs > JQuery Sliding Effect

JQuery Sliding Effect


JQuery JQuery 
Ratings:
0 Comment(s)
 2053  View(s)
Rate this:

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.

Example

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">

    <title></title>

    <script src="SCRIPT/jquery-1.11.0.min.js"></script>

    <script type="text/javascript">

        $(document).ready(function () {

            $("#CollapseHeader").click(function () {

                $("#contentArea").slideToggle("slow");

            });

            $("#Close").click(function () {

                $("#contentArea").slideUp(100);

            });

        });

    </script>

</head>

<body>

    <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>

            <div id="contentArea">

                <div align="right">

                    <a id="Close"

                        href="#" style="font-size: 10px;">Close</a>

                </div>

                Content of Collapse Box<br />

                This collapse box will slide up when you click on "Click Here"

            </div>

        </div>

    </form>

</body>

</html>

Output

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:



Don't want to miss updates? Please click the below button!

Follow MindStick