Javascript 调用在Jquery中不作为链接函数使用
我有以下代码片段:Javascript 调用在Jquery中不作为链接函数使用,javascript,jquery,Javascript,Jquery,我有以下代码片段: $('#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).
$('#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);
现在,在$('#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()上使用调用函数
函数支持回调函数。你可以利用这个。所以你可以这样用
$('#move').click(function(){
$('#block').animate({ 'left' : '+=50px' } , 500, function(){
get_fx();
});
谢谢你的投票,这真的鼓励我学习更多,我是Jquery的新手,非常感谢你。不过也请回答这个问题。比如?@ArunPJohny谢谢,为什么我的代码中会显示错误?我创建了一个名为
call
的插件,它正在执行调用get\u fx
的实际工作。如果这解决了问题,我可以将其作为answer@ArunPJohny我在你的小提琴里没有看到任何外部资源的插件,你没有使用调用函数是javascript,即prototype.call()?谢谢!但是我真的想使用call()函数。我知道回调选项。不过我会投票支持你的。
$('#move').click(function(){
$('#block').animate({ 'left' : '+=50px' } , 500, function(){
get_fx();
});