天天看點

圖檔格式的相容性問題

PNG圖檔有很好的品質。陰影效果也不會有雜邊,很流暢。如果插入網頁的話可以給網站内容增色不少!更重要的是在不增加圖檔容量大小的情況下提高了頁面的圖檔的品質。對于有複雜背景,如:在有顔色過度背景上插入不規則邊框的圖檔帶來極大很便利!

但目前IE中對于插入的透明背景的.png的圖檔是不能正常顯示的。IE會自動給”.png”格式的圖檔加個灰色背景。

解決這個的方法是增加javascript。具體方法如下:

<script language=”javascript”> 
function correctPNG()  
{  
for(var i=0; i<document.images.length; i++)  
{  
 
var img = document.images[i];  
var imgimgName = img.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.parentNode.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=’scale’);\”></span>”;  
img.outerHTML = strNewHTML ;  
 
}  
}  
}  
</script> 
           

也可以把這段代碼單獨加在一張圖檔上:

<span style="filter:progid:   
DXImageTransform.Microsoft.AlphaImageLoader  
(src='male.png', sizingMethod='scale');"> </span>       

繼續閱讀