Apply the AlphaImageLoader for transparent PNGs in IE6
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
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)
There are hundreds of scripts that do this already for you already.
Try this one: http://www.dillerdesign.com/experiment/DD_belatedPNG/
精彩评论