Posted By

merrittwjm on 03/18/11


Tagged

javascript js fade fadein fadeout


Versions (?)

Javascript Fade


 / Published in: JavaScript
 

  1. setOpacity(div, 100);
  2. fade(divId,100,"out",0);
  3.  
  4.  
  5. function setOpacity(obj, opacity) {
  6. opacity = (opacity == 100)?99.999:opacity;
  7.  
  8. // IE/Win
  9. obj.style.filter = "alpha(opacity:"+opacity+")";
  10.  
  11. // Safari<1.2, Konqueror
  12. obj.style.KHTMLOpacity = opacity/100;
  13.  
  14. // Older Mozilla and Firefox
  15. obj.style.MozOpacity = opacity/100;
  16.  
  17. // Safari 1.2, newer Firefox and Mozilla, CSS3
  18. obj.style.opacity = opacity/100;
  19. }
  20.  
  21. function fade(objId,opacity,dir,minmax)
  22. {
  23. if (document.getElementById) {
  24. obj = document.getElementById(objId);
  25. switch (dir){
  26. case "in" :
  27. if (opacity <= minmax) {
  28. setOpacity(obj, opacity);
  29. opacity += 10;
  30. setTimeout("fade('"+objId+"',"+opacity+",'in',"+minmax+");", 50);
  31. }
  32. break;
  33.  
  34. case "out" :
  35. if (opacity >= minmax) {
  36. setOpacity(obj, opacity);
  37. opacity -= 10;
  38. setTimeout("fade('"+objId+"',"+opacity+",'out',"+minmax+");", 50);
  39. }
  40. break;
  41. }
  42. }
  43. }

Report this snippet  

You need to login to post a comment.