How Can I Use FadeIn Method In JQuery With Example

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

InjQuery fadeIn() method is used to fade in a hidden element.so today we discuss how to use it

How Can I Use FadeIn Method In JQuery With Example

Syntax:

$(selector).fadeIn(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 fadeIn() method with different parameters:

Example(1)

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;display:none;background-color:red;"></div><br>
<div id="div2" style="width:80px;height:80px;display:none;background-color:green;"></div><br>
<div id="div3" style="width:80px;height:80px;display:none;background-color:blue;"></div>


Step 2:Implement jquery to show div boxes with different colors .

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


Complete Code For FadeIn Method In JQuery With Example

<!DOCTYPE html>
<html>
<head>
    <title>How Can I Use FadeIn 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">How Can I Use FadeIn 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;display:none;background-color:red;"></div>
        <br>
        <div id="div2" style="width:80px;height:80px;display:none;background-color:green;"></div>
        <br>
        <div id="div3" style="width:80px;height:80px;display:none;background-color:blue;"></div>

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

 

Related Post