Home >>jQuery Tutorial >jQuery fadeTo() method

jQuery fadeTo() method

jQuery fadeTo() method

jQuery fadeTo() method in jQuery is an inbuilt method which is used to gradually changes the opacity (fading to a given opacity), of the selected elements.

Syntax:
$(selector).fadeTo(speed,opacity,easing,callback)

Parameter Values

Parameter Description
speed It is an optional parameter and is used to Specify the speed of the fading effect. Its default value is 400 milliseconds

Possible values:

  • milliseconds
  • "slow"
  • "fast"
easing It is an optional parameter and is Specify the speed of the element in points of the animation. Its Default value is "swing"

Possible values:

  • "swing" - faster in the middle, moves slower at the beginning
  • "linear" – it moves in a constant speed
callback It is an optional parameter. After the fadeTo() method is completed a function to be executed
Here is an Example of jQuery Effect fadeTo() Method:

<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("button").click(function(){
$("h1").fadeTo(1000, 0.4);
});
});
</script>
</head>
<body>
<button>click me te see effect</button>
<h1>PHPTPOINT</h1>
</body>
</html>

Output:

PHPTPOINT

Example 2:

<html> 
<head> 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
</head> 
<body> 
<h4> 
click on me 
</h4> 
<h4> 
click on me 
</h4>  
<script> 
$("h4:first").click(function() { 
$(this).fadeTo("slow", 0.33); 
}); 
</script> 
</body> 
</html>

Output:

click on me

click on me


No Sidebar ads