We Recommend

Pro JavaScript Techniques Pro JavaScript Techniques
Pro JavaScript Techniques is the ultimate JavaScript book for the modern web developer. It provides everything you need to know about modern JavaScript, and shows what JavaScript can do for your web sites. This book doesn't waste any time looking at things you already know, like basic syntax and structures.


Posted By

mifly on 03/13/08


Tagged

javascript


Versions (?)


Who likes this?

1 person has marked this snippet as a favorite

joomla


fade in


Published in: JavaScript 


  1. function fadeIn( elem ) {
  2. // Start the opacity at 0
  3. setOpacity( elem, 0 );
  4.  
  5. // Show the element (but you can see it, since the opacity is 0)
  6. show( elem );
  7.  
  8. // WeŐre going to do a 20 ÔframeŐ animation that takes
  9. // place over one second
  10. for ( var i = 0; i <= 100; i += 5 ) {
  11. // A closure to make sure that we have the right ÔiŐ
  12. (function(){
  13. var pos = i;
  14.  
  15. // Set the timeout to occur at the specified time in the future
  16. setTimeout(function(){
  17.  
  18. // Set the new opacity of the element
  19. setOpacity( elem, pos );
  20.  
  21. }, ( pos + 1 ) * 10 );
  22. })();
  23. }
  24. }

Report this snippet 

You need to login to post a comment.