IE浏览器下的CSS问题小结( 四 )



-------------------------------------------------------------------------------------------------------

让IE6支持PNG格式的图片

用法:

先复制下面的代码在记事本中,然后另存为pngbehavior.htc(名字可以任意):

复制代码代码如下:
public:component lightWeight="true"
public:attach event="onpropertychange" onevent="propertyChanged()" /
public:attach event="onbeforeprint" onevent="beforePrint()" for="window"/
public:attach event="onafterprint" onevent="afterPrint()" for="window"/
script
var supported = /MSIE ((5.5)|[6789])/.test(navigator.userAgent)
navigator.platform == "Win32";
var realSrc;
var blankSrc = "https://www.rkxy.com.cn/dnjc/blank.gif";
var isPrinting = false;
if (supported) fixImage();
function propertyChanged() {
if (!supported || isPrinting) return;
var pName = event.propertyName;
if (pName != "src") return;
// if not set to blank
if (!new RegExp(blankSrc).test(src))
fixImage();
};
function fixImage() {
// get src
var src = https://www.rkxy.com.cn/dnjc/element.src;
// check for real change
if (src =https://www.rkxy.com.cn/dnjc/= realSrc/.png$/i.test(src)) {
element.src = https://www.rkxy.com.cn/dnjc/blankSrc;
return;
}
if ( ! new RegExp(blankSrc).test(src)) {
// backup old src
realSrc = https://www.rkxy.com.cn/dnjc/src;
}
// test for png
if (/.png$/i.test(realSrc)) {
// set blank image
element.src = https://www.rkxy.com.cn/dnjc/blankSrc;
// set filter
element.runtimeStyle.filter = "progid:DXImageTransform.Microsoft."
"AlphaImageLoader(src=https://www.rkxy.com.cn/dnjc/’"src"’,sizingMethod=’scale’)";
}
else {
// remove filter
element.runtimeStyle.filter = "";
}
}
function beforePrint() {
isPrinting = true;
element.src = https://www.rkxy.com.cn/dnjc/realSrc;
element.runtimeStyle.filter = "";
realSrc = https://www.rkxy.com.cn/dnjc/null;
}
function afterPrint() {
isPrinting = false;
fixImage();
}
/script
/public:component


最后在你的css文件里面加上这么一段代码:
img {behavior: url(pngbehavior.htc);}

推荐阅读