views:

27

answers:

2

I have been trying for some time to get the AlphaImageLoader to work with my s in IE6.

One of the solutions I was trying suggests applying the AlphaImageLoader and then the Opacity(0). This would essentially put the transparent png in the background and make the orginal png disappear. When I try this the image just disappears. Omitting the Opacity filter has no effect and the png is still not transparent. Come someone plz help?

                                                    <img id="NavBox_topLeft.png" src="#" width="17" height="34"  class="png summaryimgsrc1"

style="filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='../../../1.75/commondata/sharedimages/summary/NavBox_topLeft.png', sizingMethod='scale');"/>
    </td>

I am trying this in the markup to test. Ultimatley it will be added with JS.

Thanks

A: 

There are hundreds of scripts that do this already for you already.

Try this one: http://www.dillerdesign.com/experiment/DD_belatedPNG/

David Murdoch
I haven't found one that works. Some work for background images and not for imgs etc. Ill take a look at this one too.
Nick
A: 

Give this a try:

// Transparent PNG for IE
// http://vbence.web.elte.hu/ie_png_alpha.html

function alphaFixIE() {
    var s, i, j;

    // IMG
    var els = document.getElementsByTagName("IMG");
    for (i=0; i<els.length; i++) {
        s = els[i].src;
        if (s.toLowerCase().indexOf(".png") != -1) {
            els[i].src = "spacer.gif";
            els[i].style.filter += "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + s + "', sizingMethod=image);";
        }
    }

    // CSS: background
    for (i=0; i<document.styleSheets.length; i++) {
        var pos = document.styleSheets[i].href.lastIndexOf("/");
        var cssDir = (pos != -1) ? document.styleSheets[i].href.substring(0, pos + 1) : "";
        for (j=0; j<document.styleSheets[i].rules.length; j++) {
            var style = document.styleSheets[i].rules[j].style;
            if (style.backgroundImage.toLowerCase().indexOf(".png") != -1) {
                var filename = style.backgroundImage.substring(4, style.backgroundImage.length - 1);
                if (filename.indexOf("http://") != 0 && filename.indexOf("/") != 0)
                    filename = cssDir + filename;
                style.backgroundImage = "none";
                style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + filename + "', sizingMethod='crop');";
            }
        }
    }
}

if (navigator.userAgent.indexOf("MSIE") != -1 && navigator.userAgent.indexOf("Windows") != -1)
    window.attachEvent("onload", alphaFixIE);

Note: don't forget to add a spacer.gif to the same directory.

(maybe the browser/feature detection part can be improved a bit, but it works)

galambalazs
Dude.. you rock. This is essentially what I had but I think I was using the sizingMethod argument incorrectly. sizingMethod='image' was set to 'scale' so all my backgrounds where working but the images were not. The only thing that I had to add to your script above was: $(".curvepanel,.prescriptionheader,.navHeader").css("background-image", "none");I found it necessary to set the background-image to none to see the underlying background behind the pngs. Thanks a ton.
Nick
no prob', dude :)
galambalazs