Alpha PNG Backgrounds in IE, another sleight update…
A couple years ago Drew McLellan created his version of Youngpup’s Sleight script for enabling PNG transparency in Internet Explorer. It's a handy little thing, it's called bgsleight.js and I found myself using it for a recent project that required a decent amount of transparency in background images throughout. The great thing about bgsleight is that you don't have to generally create a separate css file for IE6 filled with progid:DXImageTransform.Microsoft.AlphaImageLoader garbage.
Some of these background images were specifically positioned, and some were repeating (not for pattern, but just coverage of their element's area). After putting Drew's work to use, I found that the background images that were being repeated in my css, were now basically gone (or just being displayed as the very small versions of themselves that they are, just a couple of pixels large). I looked into the pngfix function, and added a check against whether or not the background image was supposed to be repeating or not.
-
function fnFixPng(obj) {
-
var bg = obj.currentStyle.backgroundImage;
-
var src = bg.substring(5,bg.length-2);
-
var sizingMethod = (obj.currentStyle.backgroundRepeat == "no-repeat") ? "crop" : "scale";
-
obj.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "', sizingMethod='" + sizingMethod + "')";
-
obj.style.backgroundImage = "url(path/to/transparent.gif)";
-
}
One thing that I forgot to mention is that a transparent 1x1 pixel gif is required to make this script work. i changed the references to it which had previously been x.gif and blank.gif to path/to/transparent.gif... a generic reference (for you understand to replace with whatever path you'd like).
You can grab my copy of bgsleight.js here.
-
Marli
-
Tejas
-
digi
-
Imran Hossain
-
PaySo
-
John Svid
-
Joel
-
Joel
-
Spencer Barfuss
-
Daniel Kedinger
-
dano
-
Paul
-
LorD
-
Brenna Saunders
-
POSSUM4ALL
-
nater kane
-
alex
