知识库

资源库

模板库

字体库

酷站区

讨论区
快 搜        热门搜索:
当前位置:主页 > 知识库 > 网页制作基础 > WEB设计综合 >  文章内容

IE低版本png透明背景支持

2007-06-16 来源: 网络 作者: 未知 【收藏本文】【打印

    低版本IE支持透明png格式图片的方法。

    在这里下载 pngfix.js ,在页面head加入

    <!--[if lt IE 7.]>
    <script defer type="text/javascript" src="pngfix.js"></script>
    <![endif]-->

    单页面可以直接加入

    <!--[if lt IE 7]>
    <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>
    <![endif]-->

     

    最新五条评论 点击查看全部评论评
    发表您的评论
    用户名:新注册) 密码: 匿名评论
    评论内容(不能超过250字,需审核后才会公布,请自觉遵守互联网相关政策法规。
    1:用户发表意见仅代表其个人意见,并且承担一切因发表内容引起的纠纷和责任
    2:本站管理人员有权在不通知用户的情况下删除不符合规定的评论信息或留做证据
    3:请客观的评价您所看到的资讯,提倡就事论事,杜绝漫骂和人身攻击等不文明行为