admin管理员组

文章数量:1416050

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()

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()
Share Improve this question asked Sep 12, 2011 at 2:13 stefmikhailstefmikhail 7,15513 gold badges49 silver badges61 bronze badges 1
  • 1 Even though browsers implement opacity differently, all browsers implement it. So it's a matter of detecting and implmenting the correct type for the browser/version, not a matter of it being inline/block level attributes. – Jared Farrish Commented Sep 12, 2011 at 2:17
Add a ment  | 

2 Answers 2

Reset to default 8

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);

It does use CSS opacity!

Check out the source code here: http://code.jquery./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);
},

本文标签: javascriptHow does jQuery fadeTo() workStack Overflow