PDA

View Full Version : png transparency??



kyllle
Oct 13th, 2008, 10:45 PM
Hi guys,

How do i make my image transparent in ie? http://www.glen-lodge.co.uk/revamp/index.html

BoldUlysses
Oct 13th, 2008, 10:49 PM
Add this script:


<!--[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 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);
</script>
<![endif]-->

Ideally, you'd place it in an external .js file and link it.

kyllle
Oct 13th, 2008, 11:17 PM
Hi and thanks for the code, I placed it in an external file and called it from my index page but it doesnt seem to work??

Graft-Creative
Oct 14th, 2008, 12:40 AM
Hey kyllle,

It would really help us to help you if you could not be so vague and actually point us to the images in question :)

Found them anyway - but I have to ask: why the need for transparent pngs in this situation; the four images alone add up to 137kb, but looking at your layout/design the whole page shouldn't even add up to that!

You'd be better advised - in this particular situation at least - to use jpegs, and give them margins in pixels so they line up with the background gradient.

gary

kyllle
Oct 14th, 2008, 12:35 PM
but looking at your layout/design the whole page shouldn't even add up to that

sorry but what do you mean by this?

yeah i was thinkin about just doin that but i want to learn how to overcome the png problem so thats why i focused on trying that out.

Thanks

sorry about not pointing out the images in question i forgot its only a ie 6> problem

BoldUlysses
Oct 14th, 2008, 02:38 PM
Do you have a correct DOCTYPE and does your page validate? Scripts have failed for me when I encountered those issues.

And as Gary pointed out, don't use transparent PNGs unless you absolutely have to. Usually there's another way to design the page so they're not necessary.