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

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

function init(){
var tag_ids = new Array('image_fade_1','image_fade_2');

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)


i've taken this approach

function init(){
var tags = document.getElementsByTagName("img")
if(tags[i].getAttribute('class') == 'fade'){

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;

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum