By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,466 Members | 1,128 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,466 IT Pros & Developers. It's quick & easy.

problem with bgsleight.js

P: n/a
Hi!
I'm trying to make a transparent background in a table, but it's just
not working out for me! I've found this script on a site, hacked
version of sleight.js. Which I refer to in my html. It's kind of
working I guess, it seems it replaces my background.png by x.gif, but I
just can't figure out what I'm doing wrong and why this is happening.
Is it my png that is saved wrong or should I link differently to my
background-image?

if (navigator.platform == "Win32" && navigator.appName == "Microsoft
Internet Explorer" && window.attachEvent) {
window.attachEvent("onload", alphaBackgrounds);
}

function alphaBackgrounds(){
var rslt = navigator.appVersion.match(/MSIE (\d+\.\d+)/, '');
var itsAllGood = (rslt != null && Number(rslt[1]) >= 5.5);
for (i=0; i<document.all.length; i++){
var bg = document.all[i].currentStyle.backgroundImage;
if (itsAllGood && bg){
if (bg.match(/\.png/i) != null){
var mypng = bg.substring(5,bg.length-2);
document.all[i].style.filter =
"progid:DXImageTransform.Microsoft.AlphaImageLoade r(src='"+mypng+"',
sizingMethod='scale')";
document.all[i].style.backgroundImage = "url('x.gif')";
}
}
}
}

Dec 20 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
caroliena wrote:
I'm trying to make a transparent background in a table, but it's just
not working out for me! I've found this script on a site, hacked
version of sleight.js. Which I refer to in my html. It's kind of
working I guess,
Guess again.
it seems it replaces my background.png by x.gif,
As it also should. And what else did you expect that did not work?
but I just can't figure out what I'm doing wrong and why this is
happening.
You are copying nonsensical code from somewhere without having a
minimum clue yourself.
Is it my png that is saved wrong or should I link differently to my
background-image?
Perhaps. <URL:http://jibbering.com/faq/#FAQ4_43>
if (navigator.platform == "Win32" && navigator.appName == "Microsoft
Internet Explorer" && window.attachEvent) {
window.attachEvent("onload", alphaBackgrounds);
}

function alphaBackgrounds(){
var rslt = navigator.appVersion.match(/MSIE (\d+\.\d+)/, '');
<URL:http://pointedears.de/scripts/test/whatami>
var itsAllGood = (rslt != null && Number(rslt[1]) >= 5.5);
for (i=0; i<document.all.length; i++){
var bg = document.all[i].currentStyle.backgroundImage;
if (itsAllGood && bg){
if (bg.match(/\.png/i) != null){
var mypng = bg.substring(5,bg.length-2);
document.all[i].style.filter =
"progid:DXImageTransform.Microsoft.AlphaImageLoade r(src='"+mypng+"',
sizingMethod='scale')";
document.all[i].style.backgroundImage = "url('x.gif')";
}
}
}
}


Post code indented with spaces, not tabs. The above corrected and
pretty-printed, yet untested (I have no IE here):

var len;
if (document.all && (len = document.all.length))
{
for (var i = 0; i < len; i++)
{
var
o = document.all[i],
bg = o.currentStyle.backgroundImage;

if (bg)
{
if (/\.png/i.test(bg))
{
var f;
if ((f = o.filters))
{
var mypng = bg.replace(/^\s*url\((.+)\)\s*/, "$1");
f = f.item("DXImageTransform.Microsoft.AlphaImageLoade r");

if (f)
{
f.src = mypng;
f.sizingMethod = 'scale';
f.enabled = true;
}
}

o.style.backgroundImage = 'url(x.gif)';
}
}
}
}
Read the fine manual:

<URL:http://msdn.microsoft.com/workshop/author/filter/filters.asp>
PointedEars
Dec 20 '05 #2

P: n/a
Thomas 'PointedEars' Lahn said the following on 12/20/2005 3:21 PM:
caroliena wrote:

I'm trying to make a transparent background in a table, but it's just
not working out for me! I've found this script on a site, hacked
version of sleight.js. Which I refer to in my html. It's kind of
working I guess,

Guess again.


Post code indented with spaces, not tabs. The above corrected and
pretty-printed, yet untested (I have no IE here):

var len;
if (document.all && (len = document.all.length))
{
for (var i = 0; i < len; i++)
{
var
o = document.all[i],
bg = o.currentStyle.backgroundImage;


And what, pray tell, makes you believe that because the browser supports
document.all that it supports currentStyle or .backgroundImage?

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Dec 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.