IE6下PNG图片透明显示解决方法(From QQ)

其实该问题网上一大堆解决办法,QQ首页也使用了,个人认为这种方法还是比较不错的

代码
    
    
    
    
function loadPng(o)
{
if (MiniSite.Browser.ie)
{
try
{
var img = o;
var imgName = o.src.toUpperCase();
if (imgName.substring(imgName.length - 3 ,imgName.length) == " PNG " )
{
var imgID = (img.id) ? " id=' " + img.id + " ' " : "" ;
var imgClass = (img.className) ? " class=' " + img.className + " ' " : "" ;
var imgTitle = (img.title) ? " title=' " + img.title + " ' " : " title=' " + img.alt + " ' " ;
var imgStyle = " display:inline-block; " + img.style.cssText;
if (img.align == " left " )imgStyle = " float:left; " + imgStyle;
if (img.align == " right " )imgStyle = " float:right; " + imgStyle;
if (img.parentElement.href)imgStyle = " cursor:hand; " + imgStyle;
var strNewHTML = " <span " + imgID + imgClass + imgTitle + " style=\ "" + " width: " +img.width+ " px; height: " +img.height+ " px; " +imgStyle+ " ; " + " filter:progid:DXImageTransform.Microsoft.AlphaImageLoader " + " (src = \ ' "+img.src+"\ ' , sizingMethod = ' image ' );\ " ></span> " ;
img.outerHTML
= strNewHTML;
}
}
catch (e)
{
}
}
}

 

调用的HTML如:

代码
    
    
    
    
< div class ="fl" >
< a href ="http://my2010.qq.com/" >
< img src ="http://mat1.gtimg.com/www/iskin09/iexpo.png" width ="77" height ="14" align ="absmiddle"
onload
="loadPng(this)" style ="margin-top: 4px; _margin-top: 2px;" />
</ a >
</ div >

 

你可能感兴趣的:(IE6下PNG图片透明显示解决方法(From QQ))