方法一:
将下面代码保存为correctPNG.js:
function correctPNG()
{
for(var i=0; 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 = "
+ " style=\"" + "width:" + img.width + "px; margin:6px; height:" + img.height + "px;" + imgStyle + ";" + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader" + "(src=\'" + img.src + "\', sizingMethod='scale');\"> img.outerHTML = strNewHTML i = i-1 } } } window.attachEvent("onload", correctPNG); 然后在你需要透明的网页中的
方法二:
最近做网站时,发现IE不支持PNG透明图片,其实这个问题很早就发现了这个问题,一直没有得到解决
今天去蓝色理想论坛上发贴,希望得到决于.一个朋友讲用一段JS可以实现此透明透明.看着一段JS代码发麻,
幸好在在闪吧上找到了解决方案.现在贴出来,与在家分享.
解决思路:
IE直接是不支持PNG格式的图片的透明效果的,但通过 AlphaImageLoader 滤镜可以解决这个问题。
代码示例:
PNG透明:
PNG不透明:
注意:使用本代码前必须保证PNG图片有透明的部分