2010-12-07 55 views
1
function loadIgInnerPanelMenu(panelNum){ 

    var delayTime = 300; 

    if($('#igto1 .btMenuShow').length === 0){ 

     $('#igto1 .igInnerPanelBottomMenu').append(loadIgInnerBM(panelNum)).animate({'top':419},'fast',function(){}).addClass('btMenuShow').find('.btMenu').each(function(){ 
      $(this).stop(false,true).animate({'top':0},delayTime); 
      delayTime+=100;  
     }); 
    } 
    else{  
     // using inuse to prevent the botton quick switch 
     if(inuse === false){     

      $('#igto1 .igInnerPanelBottomMenu').append(loadIgInnerBM(panelNum)).find('.btMenu:gt(3)').each(function(){ 
       $(this).stop(false,true).animate({'top':0},delayTime); 
       delayTime+=100; 
      }); 

     }   
    } 

    alert(delayTime) 

}變量值不會在jquery動畫函數中重新設置!

此功能是通過「點擊」事件中調用的。但在delayTime值不設置回300調用函數again.The後delayTime值累積。

非常感謝!

回答

1

@gin,

您聲明變量,但如果條件一直執行正確的

下面的代碼的人會爲什麼它被設置爲不同的值肯定執行和最新

刪除下面的線和打印,它應該總是打印300

delayTime+=100; 
`delyaTime=delyaTime+100;`// equivalent of above code...// you might be already knowing it 
+0

謝謝。但爲什麼delayTime + = 100會累積delayTime值? – qinHaiXiang 2010-12-07 09:11:33

0

試試這個:

function loadIgInnerPanelMenu(panelNum){ 

    var delayTime; 

    if($('#igto1 .btMenuShow').length === 0){ 

$('#igto1 .igInnerPanelBottomMenu').append(loadIgInnerBM(panelNum)).clearQueue(); 
delayTime = 300; 

     $('#igto1 .igInnerPanelBottomMenu').append(loadIgInnerBM(panelNum)).animate({'top':419},'fast',function(){}).addClass('btMenuShow').find('.btMenu').each(function(){ 
      $(this).stop(false,true).animate({'top':0},delayTime); 
      delayTime+=100;  
     }); 
    } 
    else{  
     // using inuse to prevent the botton quick switch 
     if(inuse === false){     

      $('#igto1 .igInnerPanelBottomMenu').append(loadIgInnerBM(panelNum)).find('.btMenu:gt(3)').each(function(){ 
$(this).stop(false,true).clearQueue(); 
delayTime = 300; 
       $(this).stop(false,true).animate({'top':0},delayTime); 
       delayTime+=100; 
      }); 

     }   
    } 

    alert(delayTime) 
}