我只是想知道当jQuery不支持opacity
时如何在IE浏览器中生成淡入淡出效果?动画opacity
是他们在Firefox和Chrome等其他浏览器中淡出的方式。
我进入了代码,但老实说,我找不到任何可以理解的东西!
答案 0 :(得分:9)
从jquery源代码,它们基本上检测是否支持不透明度,如果不支持,则使用IEs alpha filter
if ( !jQuery.support.opacity ) {
jQuery.cssHooks.opacity = {
get: function( elem, computed ) {
// IE uses filters for opacity
return ropacity.test( (computed && elem.currentStyle ? elem.currentStyle.filter : elem.style.filter) || "" ) ?
( parseFloat( RegExp.$1 ) / 100 ) + "" :
computed ? "1" : "";
},
set: function( elem, value ) {
var style = elem.style,
currentStyle = elem.currentStyle;
// IE has trouble with opacity if it does not have layout
// Force it by setting the zoom level
style.zoom = 1;
// Set the alpha filter to set the opacity
var opacity = jQuery.isNaN( value ) ?
"" :
"alpha(opacity=" + value * 100 + ")",
filter = currentStyle && currentStyle.filter || style.filter || "";
style.filter = ralpha.test( filter ) ?
filter.replace( ralpha, opacity ) :
filter + " " + opacity;
}
};
}
答案 1 :(得分:3)
使用以下样式filter:alpha(opacity=40)