png透明图片如何在ie中透明显示

今天在对付png在ie中透明的战斗中,我们使用了js.
看如下代码

今日更新
--------------------------------
用css来定义也可以实现.....
hack下:

filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='**.png',sizingMethod='crop');



其实下边的js也是应用的
AlphaImageLoader
直接加到css里倒是省去js了,某些人禁用js时候要考虑这个解决方案
--------------------------------------


// JavaScript Document
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
            }
     }
  }
window.attachEvent("onload", correctPNG);


将这个代码保存成js文件 以后每次在网页中引用这个文件就可以让你的png图片透明显示了.

不会引用????


<script defer type="text/javascript" src="***/png.js"></script>


    -- S.Sams Lifexperience!
posted @ 2007-09-07 12:58 S.Sams 阅读(308) 评论(0)  编辑 收藏 网摘

标题  
姓名  
主页
Email (博主才能看到) 
验证码 *  看不清,换一张 [登录][注册]
内容(请不要发表任何与政治相关的内容)  
  登录  使用高级评论  新用户注册  返回页首  恢复上次提交      
该文被作者在 2007-09-07 13:00 编辑过
Google站内搜索

China-pub 计算机图书网上专卖店!6.5万品种 2-8折!
近千种 9-95 新二手计算图书火热销售中!
开发者征途系统新作:《设计模式——基于C#的工程化实现及扩展》



相关文章:

相关链接: