IE6 PNG 透明的方法
生活随笔
收集整理的這篇文章主要介紹了
IE6 PNG 透明的方法
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
原文地址:
http://www.cnblogs.com/majian/archive/2010/08/12/1798221.html
IE6不支持PNG半透明圖片的缺陷為web設計帶來了極大的不便,之前曾經介紹過用濾鏡+hack的方法實現顯示PNG,不過實現起來相當繁瑣。還有一種網上比較流行的方法,更加簡便,下面詳細介紹這種方法:把以下代碼保存為correctpng.js function correctPNG()
{
?? for(var i=0; i<document.images.length; i++)
?? {
?? var img = document.images[i]
?? 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
?? i = i-1
?? };
?? };
};
if(navigator.userAgent.indexOf("MSIE")>-1)
{
window.attachEvent("onload", correctPNG);
};
在網頁的頭部引用一下 <SCRIPT language=JavaScript?
src="correctpng.js"?
type=text/javascript></SCRIPT>
使用的時候直接用img標簽即可。
轉載于:https://www.cnblogs.com/chen7/p/3356373.html
總結
以上是生活随笔為你收集整理的IE6 PNG 透明的方法的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【会议记录】第二次例会(10.06)记录
- 下一篇: IconFont的使用方法