解決PNG圖片在IE6中背景不透明方法

解決PNG圖片在IE6中背景不透明方法_解決IE6中PNG背


未處理前PNG圖片在IE6中背景不透明

DIVCSS5爲大家介紹完美解決PNG圖片在IE6中背景不透明的方法_解決IE6中PNG圖片背景不透明方法-圖例

未解決PNG背景透明前截圖

解決後PNG圖片在IE6中背景透明
解決後PNG圖片背景在IE6透明截圖

目錄
  1. 解決代碼
  2. 解決png圖片在html中
  3. 解決png作爲網頁背景-css

1、解決PNG圖片在IE6中背景不透明的CSS與JS代碼   -  TOP

JS代碼

 function correctPNG() // correctly handle PNG transparency in Win IE 5.5 & 6.
{
var arVersion = navigator.appVersion.split("MSIE")
var version = parseFloat(arVersion[1])
if ((version >= 5.5) && (document.body.filters))
{
for(var j=0; j<document.images.length; j++)
{
var img = document.images[j]
var imgName = 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.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='scale');\"></span>"
img.outerHTML = strNewHTML
j = j-1
}
}
}
}
window.attachEvent("onload", correctPNG);

CSS代碼
 
 #id{background:url(圖片路徑) ;_filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled='true', sizingMethod='scale', src="圖片路徑");_background:none;}
 

 

2、解決png圖片在html中IMG標籤使用PNG圖片IE6中背景不透明方法   -  TOP

1、新建一個JS文件爲iepngfx.js,進以上JS代碼拷貝到JS文件裏
2、在HTML中聲明只有IE6讀取此新建JS文件iepngfx.js中
只允許IE6讀取此JS文件方法:
<!--[if IE 6]>
<script src="images/iepngfx.js" language="javascript" type="text/javascript"></script>
<![endif]-->
3、在html中使用圖片標籤IMG運用PNG圖片,在IE6試試看PNG圖片背景是否透明瞭。

3、在CSS中png作爲網頁背景時在IE6中背景透明方法   -  TOP

同樣方法
1、新建JS文件同上,命名爲iepngfx.js,進以上JS代碼拷貝到JS文件裏
2、在HTML中聲明只有IE6讀取此新建JS文件iepngfx.js中
只允許IE6讀取此JS文件方法:
<!--[if IE 6]>
<script src="images/iepngfx.js" language="javascript" type="text/javascript"></script>
<![endif]-->
3、在CSS中運用PNG圖片作爲背景的地方加入以下CSS代碼:

 #id{background:url(圖片路徑) ;_filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled='true', sizingMethod='scale', src="圖片路徑");_background:none;}
 

這樣即可解決PNG圖片在HTML中img作爲圖片圖標背景不能透明或PNG圖片作爲網頁背景background運用的一樣實現PNG圖片背景透明。

以下JS和CSS方法解決PNG圖片在IE6中背景不透明方法對你有用。

如需轉載,請註明文章出處和來源網址:http://www.divcss5.com/css-hack/c265.shtml

發佈了18 篇原創文章 · 獲贊 53 · 訪問量 10萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章