0
Expain the fade toggle method in JQuery with example.
Expain the fade toggle method in JQuery with example.
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>
