2013-06-05 68 views
1

由於我安裝了Firefox的Adblock Plus(用於阻止廣告的插件),每個由scriptaculous提供支持的動畫都不再工作(不僅在我的網站上)。檢查javascript函數是否未完成

現在我知道了,我正在尋找一種方法來檢查一個javascript函數是否沒有完成(就像我爲我的scriptaculous動畫所要求的那樣)。

<script type="text/javascript"> 

function scriptaculous(){ 

    new Effect.Morph("thumb_id", { style: "height:300px;", duration: 0.8 }); 

} 

function enlarge_thumbnail(){ 

    scriptaculous(); 

// if(scriptaculous() was not completed){ 

    document.getElementById("thumb_id").style.height = "300px"; 

// } 

} 

</script> 

真正的問題是,我不能只調用它們兩個,因爲第一個bug和第二個加載。任何人都知道如何處理?

回答

0

只要有任何效果開始等等,它們就會被添加到全局效果隊列中,這樣您就可以檢查隊列是否存在以及隊列中有多少效果。

if(Effect.Queues.get('global').effects.length == 0) 
{ 
    //do something else 

} 

也因爲影響的方法將立即返回,你不會知道什麼時候效果結束,除非你使用afterFinish回調,像這樣

new Effect.Morph("thumb_id", 
         { 
         style: "height:300px;", 
         duration: 0.8, 
         afterFinish: function(effect){ 
          //do other things when the effect is finished 
          //the callback is passed the effect object 
          //and the element it is working on is at effect.element 
         } });