变量值不会在 jquery animate 函数中设置回来!

发布于 2024-10-06 13:10:52 字数 977 浏览 4 评论 0原文

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) 

该函数由“click”事件调用。但是

再次调用该函数后,delayTime 的值并未设置回 300delayTime 值已累计。

非常感谢!!

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) 

}

this function is called by a 'click' event .but the value of delayTime doesn't set back to 300 after the function was called again.The delayTime value was cumulated.

Thank you very much!!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

烟若柳尘 2024-10-13 13:10:52

@gin,

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

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

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

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

@gin ,

you are declaring the variable but one of the if conditions are always executing right

the following code gets executed for sure and whats why it is setting to a different value

remove the below line and print , it should always print 300

delayTime+=100; 
`delyaTime=delyaTime+100;`// equivalent of above code...// you might be already knowing it
卸妝后依然美 2024-10-13 13:10:52

试试这个:

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) 
}

try this:

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) 
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文