调用在Jquery中未作为链接函数工作

Call not working as a chained function in Jquery

本文关键字:链接 函数 工作 Jquery 调用      更新时间:2023-09-26

我有以下代码片段:

$('#move').click(function () {
    $('#block').animate({
        'left': '+=50px'
    }, 500);
});
function get_fx() {
    var store = console.log($(this).queue('fx').length);
    return store;
}
function trigger_it(param) {
    $(param).trigger('click');
}
call_it = setInterval(function () {
    trigger_it('#move')
},
2000);

Fiddle Here

现在,在$('#block')上运行animate函数后,我希望get_fx()函数返回仍在$('#block')队列中的动画数量,因此在animate功能之后,我有以下代码行:

.call(this , get_fx())

现在这似乎确实有效,但让我向您展示我在控制台中得到的结果:

0 // 0 is displayed , which i guess is the correct result .. I am not sure . 
TypeError: $(...).animate(...).call is not a function // I get this error , I don't know why . 

现在有人能告诉我为什么我会出现这个错误吗?我的调用函数正在做它应该做的事情吗?

编辑::我不想使用animate函数的回调选项,而是想在get_fx()上使用调用函数。

    animate() 

函数支持回调函数。你可以利用这个。所以你可以像这样使用

        $('#move').click(function(){
            $('#block').animate({ 'left' : '+=50px' } , 500, function(){
                 get_fx();
            });