Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 1 of 1
  1. #1
    Senior Coder
    Join Date
    Apr 2005
    Posts
    1,051
    Thanks
    0
    Thanked 0 Times in 0 Posts

    a better way to pass in the objects?*fixed*

    Edit:

    Well, i got it to work with
    Code:
    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

    Code:
    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:
    Code:
    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;
    }
    Last edited by rlemon; 12-14-2005 at 09:46 PM.
    public string ConjunctionJunction(string words, string phrases, string clauses)
    {
    return (String)(words + phrases + clauses);
    }
    <--- Was I Helpfull? Let me know ---<


 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •