www.webdeveloper.com
Results 1 to 6 of 6

Thread: Fade out particular DIV

  1. #1
    Join Date
    Mar 2010
    Location
    Scotland, UK
    Posts
    3

    Fade out particular DIV

    Hey guys,

    This is my first post.
    Can somebody look over this code and tell me why its not working? When I uncomment //Itemnumber = 1;, it seems to work fine.

    Code:
    <script language="JavaScript">
    
    //fades layer out
    ie5 = (document.all && document.getElementById);
    ns6 = (!document.all && document.getElementById);
    opac2 = 100;
    
    function fadeOut(itemnumber) {
    	//document.write(opac2);
    	//itemnumber = 1;
    	var idname = "fade" + itemnumber;
    		if(opac2 > 0){
    		opac = 0;
    		opac2-=1;
    			if(ie5) document.getElementById(idname).filters.alpha.opacity = opac2;
    			if(ns6) document.getElementById(idname).style.MozOpacity = opac2/100;
    		setTimeout('fadeOut()', 0);
    		//document.write(itemnumber);
    	}
    }
    </script>
    
    <input type="button" value="Delete This User " onClick="fadeOut(1);" >
    <a href="
    <input type="button" value="Delete This User " onclick="fadeOut(2)" />
    <input type="button" value="Delete This User " onclick="fadeOut(3)" />
    <input type="button" value="Delete This User " onclick="fadeOut(4)" />
    
    
    <div id="fade1"> fade 1 here</div>
    <div id="fade2"> fade 2 here</div>
    <div id="fade3"> fade 3 here</div>
    <div id="fade4"> fade 4 here</div>
    Cheers guys,

    Mark

  2. #2
    Join Date
    Mar 2007
    Posts
    946
    Change this
    HTML Code:
    setTimeout('fadeOut()', itemnumber);
    to
    HTML Code:
    setTimeout('fadeOut()', 0);

  3. #3
    Join Date
    Mar 2010
    Location
    Scotland, UK
    Posts
    3
    Quote Originally Posted by skywalker2208 View Post
    Change this
    HTML Code:
    setTimeout('fadeOut()', itemnumber);
    to
    HTML Code:
    setTimeout('fadeOut()', 0);
    Do you mean the other way around?

    I just tried that with no success.


    This version has the buttons more nicely formatted:

    Code:
    <script language="JavaScript">
    
    //fades layer out
    ie5 = (document.all && document.getElementById);
    ns6 = (!document.all && document.getElementById);
    opac2 = 100;
    
    function fadeOut(itemnumber) {
    	//document.write(opac2);
    	itemnumber = 1;
    	var idname = "fade" + itemnumber;
    		if(opac2 > 0){
    		opac = 0;
    		opac2-=1;
    			if(ie5) document.getElementById(idname).filters.alpha.opacity = opac2;
    			if(ns6) document.getElementById(idname).style.MozOpacity = opac2/100;
    		setTimeout('fadeOut()', 0);
    		//document.write(itemnumber);
    	}
    }
    </script>
    
    <input type="button" value="Delete This User " onClick="fadeOut(1);" >
    <input type="button" value="Delete This User " onClick="fadeOut(2);" >
    <input type="button" value="Delete This User " onClick="fadeOut(3);" >
    <input type="button" value="Delete This User " onClick="fadeOut(4);" >
    
    
    
    <div id="fade1"> fade 1 here</div>
    <div id="fade2"> fade 2 here</div>
    <div id="fade3"> fade 3 here</div>
    <div id="fade4"> fade 4 here</div>

  4. #4
    Join Date
    Mar 2007
    Posts
    946
    Try this
    Code:
    setTimeout('fadeOut('+itemnumber+')', 0);
    Also, you are going to want to clear the setTimeout at some point when the item is completely fade or else you will have a never ending loop.

  5. #5
    Join Date
    Mar 2010
    Location
    Scotland, UK
    Posts
    3
    Quote Originally Posted by skywalker2208 View Post
    Try this
    Code:
    setTimeout('fadeOut('+itemnumber+')', 0);
    Also, you are going to want to clear the setTimeout at some point when the item is completely fade or else you will have a never ending loop.
    Aw sweet. How would I go about clearing that.

    Using that code works perfectly. My only problem is when I click one, and then click another. Nothing happens. Would this be solved by clearing it?

  6. #6
    Join Date
    Mar 2007
    Posts
    946
    Quote Originally Posted by coolmark18 View Post
    Aw sweet. How would I go about clearing that.

    Using that code works perfectly. My only problem is when I click one, and then click another. Nothing happens. Would this be solved by clearing it?
    I think that is the problem. Take a look at http://www.w3schools.com/js/js_timing.asp

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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



Recent Articles