欢迎坐船上岛来雨风的〓◎水中小屋◎〓 看完小屋别忘了来动漫岛论坛逛逛

使透明的PNG图片在IE上透明起来

上一篇 / 下一篇  2007-09-19 17:11:31 / 个人分类:技术文档

平常,我们经常使用Gif格式的图片以保持图片在浏览器中透明,以支持底色。但由于IE浏览器本身的原因,我们无法使透明的PNG图片透明起来,这使得PNG在网页的使用上受到了很大的局限。

在这里我介绍下:如何将它在IE浏览器下变得透明起来!

如何做?
将下面代码保存为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; margin:6px; 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);

然后在你需要透明的网页中的<head>....</head>区加入:<script. type="text/javascript" src="correctPNG.js"></script>

在<body>区加入多个与<img src="图片.png"/>类似的PNG图片就会达到PNG透明起来的效果了。

(此方法来自网上仅供参考)


TAG:

引用 删除 Guest   /   2007-11-15 13:51:12
-5
 

评分:0

我来说两句

显示全部

:loveliness: :handshake :victory: :funk: :time: :kiss: :call: :hug: :lol :'( :Q :L ;P :$ :P :o :@ :D :( :)

日历

« 2008-08-21  
     12
3456789
10111213141516
17181920212223
24252627282930
31      

数据统计

  • 访问量: 7256
  • 日志数: 54
  • 图片数: 10
  • 影音数: 3
  • 文件数: 4
  • 书签数: 5
  • 建立时间: 2006-09-12
  • 更新时间: 2008-05-27

RSS订阅

Open Toolbar