变量值不会在jquery动画函数中重新设置!

时间:2010-12-07 08:51:58

标签: jquery jquery-animate each

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) 

}

此功能由“点击”事件调用。但在再次调用该函数后,delayTime的值不会重新设置为300delayTime值已累计

非常感谢!!

2 个答案:

答案 0 :(得分:1)

@gin,

您正在声明变量,但其中一个if条件始终正确执行

以下代码肯定会被执行,为什么它设置为不同的值

删除下面的行并打印,它应该始终打印300

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

答案 1 :(得分: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) 
}