O'Reilly logo

jQuery and JavaScript Phrasebook by Brad Dayley

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Fading to a Specific Level of Opacity

$("img").fadeTo(2000, .5); $("img").fadeTo(2000, 1); $("img").fadeTo(2000, .1);

The .fadeTo( duration, opacity [, easing] [, callback]) method provides the duration and opacity options that specify a specific opacity to end at and how long to animate the transition. It also provides optional easing and callback arguments.

For example, the following code applies an animation of 2 seconds for all images to transition from the current opacity to .5:

$("img").fadeTo(2000, .5);

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required