Tangram-base
Tangram-base copied to clipboard
baidu.dom.opacity method users 'opacity:' instead of 'opacity='
In the method of baidu.dom.opacity, and it set the opacity using filter with 'xxxxx(opacity__:xxx' instead of 'xxxxx(opacity=__'. The problem is that if I set the opacity with this method, but I want to get the opacity using the baidu.dom.getStyle, and it won't work. Frankly speaking, I can't figure out why there exists a method calling baidu.dom.opacity, do you want to provide a shortcut method? or other reasons?
baidu.dom.opacity = function(element, opacity){
element = baidu.dom.g(element);
if (!baidu.browser.ie) {
element.style.opacity = opacity;
element.style.KHTMLOpacity = opacity;
} else {
element.style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity:"+
Math.floor(opacity * 100) +")";
}
};
baidu.dom._styleFixer.opacity = baidu.browser.ie ? {
get: function (element) {
var filter = element.style.filter;
return filter && filter.indexOf("opacity=") >= 0 ? (parseFloat(filter.match(/opacity=([^)]*)/)[1]) / 100) + "" : "1";
},
set: function (element, value) {
var style = element.style;
// 只能Quirks Mode下面生效??
style.filter = (style.filter || "").replace(/alpha\([^\)]*\)/gi, "") + (value == 1 ? "" : "alpha(opacity=" + value * 100 + ")");
// IE filters only apply to elements with "layout."
style.zoom = 1;
}
} : null;
thanks,
starandtina