• 在IE流览器中正确显示PNG透明图片


    png图片有很好的品质。阴影效果也不会有杂边,很流畅。如果插入网页的话可以给网站内容增色不少!更重要的是在不增加图片容量大小的情况下提高了页面的图片的质量。对于有复杂背景,如:在有颜色过度背景上插入不规则边框的图片带来极大很便利! 但目前IE中对于插入的透明背景的.png的图片是不能正常显示的。IE会自动给".png"格式的图片加个灰色背景。 解决这个的方法是增加javascript,利用IE的滤镜功能实现PNG的透明显示。具体方法如下:

       把下面的代码放在head区就可以解决问题了。
    <!--[if gte IE 5.5000]><script type="text/javascript" src="js/pngfix.js"></script><![endif]-->
    pngfix.js文件的程序代码


       本文相关代码如下:

    // 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=\"" + "" + 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);
  • 相关阅读:
    P1268 树的重量
    P2419 [USACO08JAN]牛大赛Cow Contest
    P1306 斐波那契公约数
    P2905 [USACO08OPEN]农场危机Crisis on the Farm
    P1081 开车旅行
    P2906 [USACO08OPEN]牛的街区Cow Neighborhoods
    P1550 [USACO08OCT]打井Watering Hole
    P2746 [USACO5.3]校园网Network of Schools
    P1613 跑路
    【BZOJ4868】期末考试(整数三分)
  • 原文地址:https://www.cnblogs.com/ANDY_ZHANG/p/2464832.html
Copyright © 2020-2023  润新知