Thread: image formats
View Single Post
  #3 (permalink)  
Old 02-29-2008, 09:58 AM
BigAlReturns's Avatar
BigAlReturns BigAlReturns is offline
Moderator Extraordinaire!
 
Join Date: Dec 2007
Location: The Wirral, England
Posts: 291
Send a message via MSN to BigAlReturns
Default

Quote:
Originally Posted by ryanhellyer View Post
The PNG format can also create transparencies and supports an alpha layer which allows for semi-transparent portions. However support for this format is not available in <IE6 so it isn't much use except for in particular circumstances. Once the need to support IE6 is gone, alpha level transparencies in PNG format will be very useful.
PNGs can be very useful because of their transparency, but as you've said, IE6 support is a problem. There is a javascript solution to make PNGs transparent in IE6 if you have no other option, but it's a bit long winded, and a pain in the backside! This is code I've found to work for me:

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

pngfix.js
var arVersion = navigator.appVersion.split("MSIE")
var version = parseFloat(arVersion[1])

if ((version >= 5.5) && (document.body.filters)) 
{
   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
      }
   }
}
Reply With Quote