Results 1 to 7 of 7

Thread: JavaScript: Slowly Fade Using Opacity

  1. #1
    Join Date
    Nov 2006
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default JavaScript: Slowly Fade Using Opacity

    hi, i found this script that makes text contents fade out from http://www.richardsramblings.com/?p=486

    i was wondering if its possible to make it fade in instead of fade out using this script


    script:

    Code:
    // @name      Slowly Fade
    // @version   0.88
    // @author    Richard D. LeCour
    // @namespace http://www.richardsramblings.com/?p=486
    
    
    var opacity = 99; // Avoid starting at 100% due to Mozilla bug
    var slowly = {
    	fadein : function (id) {
    		this.fadeLoop(id, opacity);
    	},
    	fadeLoop : function (id, opacity) {
    		var object = document.getElementById(id);
    		if (opacity >= 5) {
    			slowly.setOpacity(object, opacity);
    			opacity -= 4;
    			window.setTimeout("slowly.fadeLoop('" + id + "', " + opacity + ")", 99);
    		} else {
    			object.style.display = "none";
    		}
    	},
    	setOpacity : function (object, opacity) {
    		object.style.filter = "alpha(style=0,opacity:" + opacity + ")";	// IE
    		object.style.KHTMLOpacity = opacity / 100;				// Konqueror
    		object.style.MozOpacity = opacity / 100;					// Mozilla (old)
    		object.style.opacity = opacity / 100;					// Mozilla (new)
    	}
    }
    in the html
    HTML Code:
    <BODY onload=javascript:slowly.fadein('content')>
    
    <DIV id=content>
    content here
    </div>

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. #3
    Join Date
    Sep 2006
    Location
    England
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Smile

    Thanks Twey.
    Thats a useful script. It fades faster in Firefox than IE but thats nowt new!

    Regards,
    Ges.

  4. #4
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Ah, perhaps my arithmetic was a little off when calculating the filter parameter Thanks for pointing that out, I'll look into it.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  5. #5
    Join Date
    Jun 2006
    Posts
    42
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Default

    Interesting post

    What about poping up (when the mainpage of a site is opened) a message box that contents ( remind visitor an event with a coutdown before a given date ) fade out automaticly after xxx seconds.

  6. #6
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Code:
    <script type="text/javascript">
    window.onload = function() {
      setTimeout(
        function() {
          document.getElementById("msgbox").fadeThread.fadeOut(
            function() {
              this.element.style.display = "none";
            }
          );
        },
        5000
      );
    }
    </script>
    Change the number in red to the number of milliseconds to wait.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  7. #7
    Join Date
    Jun 2006
    Posts
    42
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Default

    Thank you very much , you're the best

Bookmarks

Posting Permissions

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