解決PNG圖片在IE6中背景不透明方法_解決IE6中PNG背
DIVCSS5爲大家介紹完美解決PNG圖片在IE6中背景不透明的方法_解決IE6中PNG圖片背景不透明方法-圖例
未解決PNG背景透明前截圖
解決後PNG圖片背景在IE6透明截圖
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