How Can I Use Fadeout Method In JQuery With Example

admin_img Posted By Bajarangi soft , Posted On 12-10-2020

In jQuery fadeOut() method is used to fade out a visible element.so today we discuss how to use fadeout method in jquery

How Can I Use Fadeout Method In JQuery With Example

Syntax:

$(selector).fadeOut(speed,callback);

The optional speed parameter specifies the duration of the effect. It can take the following values: "slow", "fast", or milliseconds.The optional callback parameter is a function to be executed after the fading completes.The following example demonstrates the fadeOut() method with different parameters:

Step 1:Create index.html file and implement below code.

<button class="btn btn-success">Click to fade in boxes</button>
<br><br>

<div id="div1" style="width:80px;height:80px;background-color:red;"></div><br>
<div id="div2" style="width:80px;height:80px;background-color:green;"></div><br>
<div id="div3" style="width:80px;height:80px;background-color:blue;"></div>


Step 2:Implement jquery to use Fadeout method 

<script>
    $(document).ready(function(){
        $("button").click(function(){
            $("#div1").fadeOut();
            $("#div2").fadeOut("slow");
            $("#div3").fadeOut(3000);
        });
    });
</script>


Complete Code For Fadeout Method In JQuery

<!DOCTYPE html>
<html>
<head>
    <title>How Can I Use FadeOut Method In JQuery With Example</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
</head>
<style>
    body {
        background: darkolivegreen;
    }
</style>
<body>
<div class="container">
    <br><br><br>
    <div class="text-center">
        <h2 id="color" style="color: White">Use FadeOut Method In JQuery</h2>
    </div>
    <br>
    <br>
    <div class="well">

        <button class="btn btn-success">Click to fade in boxes</button>
        <br><br>

        <div id="div1" style="width:80px;height:80px;background-color:red;"></div><br>
        <div id="div2" style="width:80px;height:80px;background-color:green;"></div><br>
        <div id="div3" style="width:80px;height:80px;background-color:blue;"></div>

    </div>
</div>
</body>
</html>
<script>
    $(document).ready(function(){
        $("button").click(function(){
            $("#div1").fadeOut();
            $("#div2").fadeOut("slow");
            $("#div3").fadeOut(3000);
        });
    });
</script>

Related Post