开发者

Solving chained callbacks in Jquery

I try to understand whats happening within this code: (This is said to be a very effective way for solving chained callbacks)

(function hidenext(jq){
    jq.eq(0).fadeOut开发者_如何学Go("fast", function(){
        (jq=jq.slice(1)).length && hidenext(jq);
    });

})($('div#bodyContent a'))

Would really appreciate some help!

Thanks, Freddie from Sweden


Hallå Freddie from Sweden

Let me see if I can re-write it for you:

function hidenext(jq){
    jq.eq(0).fadeOut("fast", function(){
        jq=jq.slice(1);
        if (jq.length !== 0) {
           hidenext(jq);
        }
   });

};
hidenext($('div#bodyContent a'));

In words: given a list of elements, fade the first one out and when that fade completes, take the list that consists of everything but the first element and, if that list is non-empty, tail-recurse.

Hope this helps.

Michael from California

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜