Javascript examples for jQuery Method and Property:fadeTo
The fadeTo() method changes the opacity to a specified value.
$(selector).fadeTo(speed, opacity, easing, callback)
Parameter | Require | Description | Value |
---|---|---|---|
speed | Required. | speed of the fading effect. | Possible values: milliseconds "slow" "fast" |
opacity | Required. | opacity to fade to. | Must be a number between 0.00 and 1.00 |
easing | Optional. | speed of the element in different points of the animation. | Default value is "swing" |
callback | Optional. | A function to be executed after the fadeTo() method is completed | a function |
Possible easing values:
The following code shows how to Gradually change the opacity of all <p> elements:
<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script> $(document).ready(function(){ $("button").click(function(){ $("p").fadeTo(1000, 0.4); });//www .j a va2 s .c o m }); </script> </head> <body> <button>Gradually change the opacity of the p element</button> <p>This is a paragraph.</p> </body> </html>