png在IE6 下無法透明的解決方法匯總
FF和IE7已經(jīng)直接支持透明的png圖了,下面這個主要是解決IE6下透明PNG圖片有灰底的
style="FILTER: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=images/fl.png')"
語法:
filter : progid:DXImageTransform.Microsoft.AlphaImageLoader ( enabled=bEnabled , sizingMethod=sSize , src=sURL )
enabled : 可選項(xiàng)。布爾值(Boolean)。設(shè)置或檢索濾鏡是否激活。true | false true : 默認(rèn)值。濾鏡激活。
false : 濾鏡被禁止。
sizingMethod : 可選項(xiàng)。字符串(String)。設(shè)置或檢索濾鏡作用的對象的圖片在對象容器邊界內(nèi)的顯示方式。 crop : 剪切圖片以適應(yīng)對象尺寸。
image : 默認(rèn)值。增大或減小對象的尺寸邊界以適應(yīng)圖片的尺寸。
scale : 縮放圖片以適應(yīng)對象的尺寸邊界。
src : 必選項(xiàng)。字符串(String)。使用絕對或相對 url 地址指定背景圖像。假如忽略此參數(shù),濾鏡將不會作用。
特性:
Enabled : 可讀寫。布爾值(Boolean)。參閱 enabled 屬性。
sizingMethod : 可讀寫。字符串(String)。參閱 sizingMethod 屬性。
src : 可讀寫。字符串(String)。參閱 src 屬性。
說明:
在對象容器邊界內(nèi),在對象的背景和內(nèi)容之間顯示一張圖片。并提供對此圖片的剪切和改變尺寸的操作。如果載入的是PNG(Portable Network Graphics)格式,則0%-100%的透明度也被提供。
PNG(Portable Network Graphics)格式的圖片的透明度不妨礙你選擇文本。也就是說,你可以選擇顯示在PNG(Portable Network Graphics)格式的圖片完全透明區(qū)域后面的內(nèi)容。
實(shí)例:解決IE6下png透明失效的問題。
CSS樣式:
.png{ _background: url(images/angel.png) no-repeat !important; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod=noscale, src="images/angel.png"); background:none; width:118px;height:133px; } .png div{position:relative;}
HTML代碼:
<div class="png"> <div> CSS 背景PNG透明 及 鏈接失效問題解決 </div> </div>
/*
兼容IE6.0、IE7.0、FF,
IE7.0和新版的FF其實(shí)是可以不加filter濾鏡直接透明的。
*/
=============================================================================
方法一:定義一個樣式,給某個div應(yīng)用這個樣式后,div的透明png背景圖片自動透明了。(注意兩處圖片的路徑寫法不一樣,本例中,icon_home.png圖片與html文件在相同目錄)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>無標(biāo)題文檔</title> <style type="text/css"> <!-- .qq { height: 90px; width: 90px; background-image: url(icon_home.png)!important;/* FF IE7 */ background-repeat: no-repeat; _filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='icon_home.png'); /* IE6 */ _ background-image: none; /* IE6 */ } --> </style> </head> <body> <div class="qq"></div> </body> </html>
方法二: 給img定義樣式,頁面上所有透明png即自動透明了。(這方法只對直接插入的圖片有效,對背景圖無效)注意,要準(zhǔn)備一個透明的小圖片transparent.gif,大小不限。必須放在和html相同的目錄
請勿大量使用,否則會導(dǎo)致頁面打開很慢!!!)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>無標(biāo)題文檔</title> <style type="text/css"> .mypng img { azimuth: expression( this.pngSet?this.pngSet=true:(this.nodeName == "IMG" && this.src.toLowerCase().indexOf('.png')>-1?(this.runtimeStyle.backgroundImage = "none", this.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + this.src + "', sizingMethod='image')", this.src = "transparent.gif"):(this.origBg = this.origBg? this.origBg :this.currentStyle.backgroundImage.toString().replace('url("','').replace('")',''), this.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + this.origBg + "', sizingMethod='crop')", this.runtimeStyle.backgroundImage = "none")),this.pngSet=true); } </style> </head> <body> 換成你的png圖片 <div class="mypng"> <img src="icon_face_07.png" width="30" height="30" /> <img src="icon_face_10.png" width="30" height="30" /> <img src="icon_face_08.png" width="30" height="30" /> </div> </body> </html>
方法三:用JS實(shí)現(xiàn),加上一段js代碼后,所有插入的透明png自動透明了.(注意,這方法也是只對直接插入的圖片有效,對背景圖無效)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>無標(biāo)題文檔</title> <script language="JavaScript"> 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); </script> <style type="text/css"> <!-- body { } --> </style></head> <body> 把圖片換成你自己的圖片 <img src="img/icon_face_03.png" width="30" height="30" /><!--把圖片換成你自己的圖片 --> <img src="img/icon_face_05.png" width="30" height="30" /> <img src="img/menu_title_over.png" width="130" height="36" /> </body> </html>
方法四
<script language="javascript"> // 修復(fù) IE 下 PNG 圖片不能透明顯示的問題 function fixPNG(myImage) { var arVersion = navigator.appVersion.split("MSIE"); var version = parseFloat(arVersion[1]); if ((version >= 5.5) && (version < 7) && (document.body.filters)) { var imgID = (myImage.id) ? "id='" + myImage.id + "' " : ""; var imgClass = (myImage.className) ? "class='" + myImage.className + "' " : ""; var imgTitle = (myImage.title) ? "title='" + myImage.title + "' " : "title='" + myImage.alt + "' "; var imgStyle = "display:inline-block;" + myImage.style.cssText; var strNewHTML = "<span " + imgID + imgClass + imgTitle + " style=\"" + "width:" + myImage.width + "px; height:" + myImage.height + "px;" + imgStyle + ";" + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader" + "(src=\'" + myImage.src + "\', sizingMethod='scale');\"></span>"; myImage.outerHTML = strNewHTML; } } window.onload=function(){ document.getElementById("top").style.height=screen.height/5+"px"; }// </script>
用法如下:
<img src="logo.png" width="328" height="325" border="0" onload="fixPNG(this)" />
以上所述就是本文的全部內(nèi)容了,希望大家能夠喜歡。
- PNGHandler-借助JS讓PNG圖在IE下實(shí)現(xiàn)透明(包括背景圖)
- IE瀏覽器打不開PNG格式圖片的解決
- IE瀏覽器PNG圖片透明效果代碼
- js png圖片(有含有透明)在IE6中為什么不透明了
- DD_belatedPNG,IE6下PNG透明解決方案(國外)
- 在IE和VB中支持png圖片透明效果的實(shí)現(xiàn)方法(vb源碼打包)
- ie6下png圖片背景不透明的解決辦法使用js實(shí)現(xiàn)
- jQuery 淡入淡出 png圖在ie8下有黑色邊框的解決方法
- 解決IE6的PNG透明JS插件使用介紹
- 基于Unit PNG Fix.js有時候在ie6下不正常的解決辦法
- JS解決ie6下png透明的方法實(shí)例
- IE瀏覽器下PNG相關(guān)功能
相關(guān)文章
JavaScript中動態(tài)向表格添加數(shù)據(jù)
本文給大家分享使用原生javascript實(shí)現(xiàn)動態(tài)向表格中添加數(shù)據(jù)的方法,代碼簡單易懂,非常不錯,具有參考借鑒價值,需要的的朋友參考下吧2017-01-01js實(shí)現(xiàn)鼠標(biāo)左右移動,圖片也跟著移動效果
本文主要介紹了js實(shí)現(xiàn)鼠標(biāo)左右移動,圖片也跟著移動效果的方法與思路。具有很好的參考價值,下面跟著小編一起來看下吧2017-01-01Vue之vue-tree-color組件實(shí)現(xiàn)組織架構(gòu)圖案例詳解
這篇文章主要介紹了Vue之vue-tree-color組件實(shí)現(xiàn)組織架構(gòu)圖案例詳解,本篇文章通過簡要的案例,講解了該項(xiàng)技術(shù)的了解與使用,以下就是詳細(xì)內(nèi)容,需要的朋友可以參考下2021-09-09修改layui的后臺模板的左側(cè)導(dǎo)航欄可以伸縮的方法
今天小編就為大家分享一篇修改layui的后臺模板的左側(cè)導(dǎo)航欄可以伸縮的方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2019-09-09JavaScript中無法通過div.style.left獲取值的解決方法
這篇文章主要介紹了JavaScript中無法通過div.style.left獲取值的問題分析及解決方法,需要的朋友可以參考下2017-02-02