...

View Full Version : a better way to pass in the objects?*fixed*



rlemon
12-14-2005, 07:05 PM
Well, i got it to work with


function init(){
var tag_ids = new Array('image_fade_1','image_fade_2');
for(i=0;i<tag_ids.length;i++){
setOpacity(document.getElementById(tag_ids[i]),65);
}
return;
}




Hey everyone,
I have a site that needs some fade effects on the images -
I have a opacity function that works fine however when attempting to pass in the object i keep returning errors.

if i pass in the id of the element and create the object via
var obj = document.getElementById(id);

i get obj is null or not an object.

if i pass in the object via
var obj = document.getElementById("object_id_value");
setOpacity(obj,75); // where 75 is the percentage of opacity i wish to set the image too.

i get the same error.

however using

<img onLoad="setOpacity(this,75)" ...

works (but onLoad is not a valid img attribute)


sooooo....

i've taken this approach




function init(){
var tags = document.getElementsByTagName("img")
for(i=0;i<tags.length;i++){
if(tags[i].getAttribute('class') == 'fade'){
setOpacity(tags[i],50);
}
}
return;
}



then i've set the images that i want to fade to have class="fade"

now the problem is this:

i have to create and store all image objects in memory before i can fade the applicable images. this can be a big preformance hinderance if i have many images on the site (which, some pages may)...

if anyone else can think of a better way to do this please let me know


fyi - the setOpacity function:


function setOpacity(obj, opacity) {
opacity = (opacity == 100)?99.999:opacity;
obj.style.filter = "alpha(opacity:"+opacity+")";
obj.style.KHTMLOpacity = opacity/100;
obj.style.MozOpacity = opacity/100;
obj.style.opacity = opacity/100;
return;
}



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum