开发者

jquery fadeIn() from opacity: 0.1 - possible?

开发者 https://www.devze.com 2023-01-05 22:48 出处:网络
I\'m looking to fadeIn() a div that starts of on opacity: 0.1 or (filter: alpha(opacity = 10) in ie).

I'm looking to fadeIn() a div that starts of on opacity: 0.1 or (filter: alpha(opacity = 10) in ie).

I know i can do .animate({css.... with an if(supports opacity) but i'm looking for a quick and easy cross brows开发者_如何学编程er solution, and i imagine jquery already has one?


You can do this using .animate():

.animate({ opacity: 1 });

There no need to check $.support.opacity, it'll use the alpha filter version if needed, jQuery normalizes this internally. To be clear, this supports all browsers, including IE. You can test it here.

Edit: re-reading your question it seems these styles may be in the stylesheet, not set by .css(), in which case just add a zoom: 1 for IE to fade correctly, you can view a demo of that here. You can see how the guts of it work here.


time = 1000; // time in ms to fade from 0.1 to 1
$("#id").fadeTo(0, 0.1).fadeTo(time, 1)


You can set the opacity using css then begin the fadeIn

E.g.

yourElement.css('opacity', .1).fadeIn();
0

精彩评论

暂无评论...
验证码 换一张
取 消