.fadeTo()
JQ Home <<
Effects <<
.fadeTo()
Fading elements to an opacity.
Description
The .fadeTo()
method is used to adjust the opacity of the matched set.
Syntax
Signature | Description |
---|---|
.fadeTo( duration, opacity [, easing] [, callback] ) | Adjust the opacity of the matched set, optionally providing an easing and/or a callback function. |
Parameters
Parameter | Description | Type |
---|---|---|
duration | A string or number determining the time the animation will run for. default: 400
| String orNumber |
opacity | A number between 0 and 1 denoting the target opacity. | Number |
easing | Specify the speed at which the animation progresses at different points within the animation. default: swing
| String |
callback | A function that fires once the animation is complete.
|
Function |
Return
A jQuery
object.
.fadeTo( duration, opacity [, easing] [, callback] )
Example
Effects << Top
Adjust the opacity of the matched set, optionally providing an easing and/or a callback function.
In the example below when the left button is pressed we fade the first image to an opacity of 0.75 with a slow duration.
When the middle button is pressed we use 'swing' easing with an opacity of 0.3 with a fast duration.
When the right button is pressed we use a duration, easing and a callback to fade the last 3 images to their specified values.





$(function(){
$('#btn13').on('click', function() {
$('#curry4').fadeTo('slow', 0.75);
});
$('#btn14').on('click', function() {
$('#pie10').fadeTo('fast', 0.3, 'swing');
});
$('#btn15').on('click', function() {
$('.pie11').first().fadeTo('fast', 0.8, 'linear', function() {
// using 'callee' so we don't have to name the function
$(this).next().fadeTo(1200, 0.4, arguments.callee);
});
});
});
Related Tutorials
jQuery Intermediate Tutorials - Lesson 7 - Fading & Sliding Effects