2011-08-09 7 views
6

Solo quería saber cómo jQuery puede generar un efecto de desvanecimiento en los navegadores IE cuando no son compatibles con opacity? Animar opacity es la forma en que hacen el fundido en otros navegadores como Firefox y Chrome. Ingresé al código pero, sinceramente, ¡no pude encontrar nada comprensible para mí!¿Cómo jQuery se "desvanece" en IE8 y abajo?

Respuesta

9

Desde la fuente jquery, que básicamente detectar si se admite la opacidad y si no, use el filtro alfa IEs

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; 
    } 
}; 
} 
3

usando el siguiente estilo filter:alpha(opacity=40)