发新话题
打印

PNG透明图片在IE游览器中也能正确显示

PNG透明图片在IE游览器中也能正确显示

到目前为止,IE还不支持显示PNG透明图片,日前在http://homepage.ntlworld.com看到了一则解决方法,加一个JS文件,就能解决,IE>=5.5。如下图是透明的PNG32格式。

<!--[if gte IE 5.5000]><script type="text/javascript" src="tour/pngfix.js"></script><![endif]-->

复制内容到剪贴板
代码:

以下是代码片段:
// Correctly handle PNG transparency in Win IE 5.5 or higher.
// http://homepage.ntlworld.com/bobosola. Updated 02-March-2004
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);



把上面的代码放在head区,下载pngfix.js(※来源:中国Photoshop资源网 http://www.86ps.com※)
   
 秋风起,黄叶飞,思绪飞满天...

TOP

发新话题