Posted By

luman on 06/30/06


Tagged

hack ie image png transparency


Versions (?)

Who likes this?

5 people have marked this snippet as a favorite

helle
postNuKe
j4k
visualAesthetic
vali29


PNG transparency IE 5.5


 / Published in: JavaScript
 

  1. <!--[if gte IE 5.5000]>
  2. <script language="JavaScript">
  3. function correctPNG() // correctly handle PNG transparency in Win IE 5.5 or higher.
  4. {
  5. for(var i=0; i<document.images.length; i++)
  6. {
  7. var img = document.images[i]
  8. var imgName = img.src.toUpperCase()
  9. if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
  10. {
  11. var imgID = (img.id) ? "id='" + img.id + "' " : ""
  12. var imgClass = (img.className) ? "class='" + img.className + "' " : ""
  13. var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
  14. var imgStyle = "display:inline-block;" + img.style.cssText
  15. if (img.align == "left") imgStyle = "float:left;" + imgStyle
  16. if (img.align == "right") imgStyle = "float:right;" + imgStyle
  17. if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
  18. var strNewHTML = "<span " + imgID + imgClass + imgTitle
  19. + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
  20. + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
  21. + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>"
  22. img.outerHTML = strNewHTML
  23. i = i-1
  24. }
  25. }
  26. }
  27. window.attachEvent("onload", correctPNG);
  28. </script>
  29. <![endif]-->

Report this snippet  

You need to login to post a comment.