2011-11-26 6 views
-1
function fade(obj, time) { 
    if(this) { //prevents the function from being called too many times at once 
     addCallData(this); 
    } 
    if(!obj || !time) { 
     alert("Object/time parameters are required.\n"); 
     return false; 
    } else { 
     if(!func_data[this]["fade"]) { /*if fade is not defined for [this], then define it*/ 
      func_data[this]["fade"] = ((obj.style.opacity)?1:(obj.style.filter)); 
     } else { 
      if(func_data[this]["fade"] <= 0) { /*if object opacity has declined completely, then hide/remove the element to indicate that the object has faded*/ 
       obj.style.display="none"; 
       return false; 
      } 
      func_data[this]["fade"]=((func_data[this]["fade"])--); /*gradually reduce fade*/ 
      ((obj.style.filter)?((obj.style.filter)=func_data[this]["fade"]): 
      (obj.style.filter("alpha(opacity="+(func_data[this]["fade"])+""))); /*ultimately, set opacity to x-0.1 or x-1*/ 
      setTimeout(function(){fade(obj, time);}, time); /*loop until false occurs*/ 
     } 
    }  
} 

왜 이것이 작동하지 않는 지 잘 모르겠습니다. func_data[this]["fade"]을 0.50으로 설정할 수 있으며 HTML 요소가 불투명도의 50 %를 잃지 만 해당 속성의 값을 불투명도로 설정하면 함수가 멈추고 제한 시간 단계에 도달하지 않습니다.함수에서 자바 스크립트 설정 불투명도

+0

가 작동하지 않습니다 @DrStrangeLove. – user784446

+0

i'if (this)'는 완전히 쓸모가 없습니다. '이'는 언제나 진실 인 대상으로 강요 받는다. – pimvdb

+0

@pimvdb에서 설명을 제공 할 수 있습니까? – user784446

답변

0

확인이 : 참조에서

 
function setOpacity(value) { 
    testObj.style.opacity = value/10; 
    testObj.style.filter = 'alpha(opacity=' + value*10 + ')'; 
} 

가 : http://www.quirksmode.org/js/opacity.html

+0

이것은 작동하지 않습니다 (y는 전역 범위에 있습니다) : function fade (obj, time) { if (y <= 0) {return false;} y = ((y) -0.1); obj.style.opacity = y; setTimeout (function (obj, time) {fade (obj, time);}, 50); } – user784446

관련 문제