Expain the fade toggle method in JQuery with example.

0 votes
49 views
Ethan Karla asked 28-Jul-2021 in Web Application by Ethan Karla

Expain the fade toggle method in JQuery with example.

1 Answer

1 votes
Ravi Vishwakarma answered 29-Jul-2021 by Ravi Vishwakarma
jQuery fadeToggle()
 jQuery's fadeToggle() method is used for fadeIn() and fadeOut(). If the element is visible for some time then it will be hidden and if it is hidden for some time then it will show
Syntax:

$(selector).fadeToggle();
$(selector).fadeToggle(speed,callback);
Speed and callback is an optional parameter. Speed specifies the delay of showing elements these possible vales are 'slow', 'fast' and milliseconds. Callback function to be called after completion of fadeIn() or fadeOut(). We also put true and false value for showing and hiding element respectively.
<!DOCTYPE html>

<html>
<head>
<script src='https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js'></script>
<script>
    $(document).ready(function () {
        $('button').click(function () {
            $('#div1').fadeToggle();
            $('#div2').fadeToggle('slow');
            $('#div3').fadeToggle(2000);
            $(this).text() == 'Click to fadeIn' ? $(this).text('Click to fadeOut') : $(this).text('Click to fadeIn') ;
        });
    });
</script>
</head>
<body>
<button>Click to fadeIn</button><br><br>
<div id='div1' style='width:80px;height:80px;background-color:pink;'></div>
<br>
<div id='div2' style='width:80px;height:80px;background-color:red;'></div>
<br>
<div id='div3' style='width:80px;height:80px;background-color:black;'></div>
</body>
</html>
Expain the fade toggle method in JQuery with example.