Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does jQuery .fadeTo() work?

I'm curious how .fadeTo() fades an element? Does it use an inline style of opacity to do this?

And if it does not use css opacity, then how would you control css opacity using jQuery or javascript?

This question is referring to all of the following:

.fadeTo()
.fadeIn()
.fadeOut()
like image 279
stefmikhail Avatar asked Sep 12 '11 02:09

stefmikhail


2 Answers

From the jQuery source - CSS opacity.

fadeTo: function( speed, to, easing, callback ) {
    return this.filter(":hidden").css("opacity", 0).show().end()
                .animate({opacity: to}, speed, easing, callback);
like image 162
Joe Avatar answered Sep 28 '22 02:09

Joe


It does use CSS opacity!

Check out the source code here: http://code.jquery.com/jquery-latest.js

And search for fadeTo.

You will see (as of today, anyway):

fadeTo: function( speed, to, easing, callback ) {
    return this.filter(":hidden").css("opacity", 0).show().end()
        .animate({opacity: to}, speed, easing, callback);
},
like image 36
Ray Toal Avatar answered Sep 28 '22 03:09

Ray Toal