Open In App

jQuery | Animation, Slide methods with Examples

jQuery is a very powerful JavaScript framework.Using jQuery, we can add special effects to our website or web-based application.
We can add various effects using jQuery such as hide/show, fading effects, animation, call back and many more.
For hide/show, Toggle, Fade effect.
The jQuery contains the library of several functions that provide techniques for adding animation to a web page. These include simple animation, standard animations.
In this article, we are going to learn how to add above effects to our web page.

jQuery Animation:



In jQuery, we can produce various types of animation using the animate() method. This method can produce simple to complex animation in the web page. Using animation, we can change the properties of HTML elements such as background colour, changing border styles, changing navigation properties, formatting the font properties, etc.
We apply changes to the properties by providing the styles rules in the params parameter of the method.
Syntax:

$("selector").animate({params}, speed, callback);

where



Let’s see it’s implementation with JavaScript code:
In this code, we animate the rectangle and change its shape to circle.




<!DOCTYPE html>
<html>
    
<head>
    <script src="https://ajax.googleapis.com/ajax/
                libs/jquery/3.3.1/jquery.min.js">
</script>
    <style type="text/css">
        div {
            width: 100px;
            height: 100px;
            background-color: green;
        }
    </style>
</head>
    
<body>
    <div></div>
    <br/>
    <button id="animate">Animate Me</button>
    <script type="text/javascript">
        $("#animate").click(function() {
            $("div").animate({
                    width: "200px",
                    height: "200px",
                    borderRadius: "50%",
                    marginLeft: "210px",
                    marginTop: "70px",
                },
                2000,
            );
        });
    </script>
</body>
    
</html>

Output:
Before the Animate Me is clicked


After the Animate Me is clicked

jQuery Slide:

Using jQuery , we can add the slide up or down effect in our web page . The slides are always present in the web page in the form of div pairs . There are three methods to add the sliding effects in our web page .These are as follows:
Article Tags :