开发者

JQuery fadeto animation with callback problem

Here's my code:

function hideColumnAndShowOther(columnToHide, columnToShow) {
$(columnToHide).fadeTo("slow", 0.0, f开发者_StackOverflow中文版unction() {
                       $(columnToShow).fadeIn("slow");
                       });
}

In this case the callback function isn't called. I have used the firebug tool to get the root of the problem. In the callback function the 'columnToShow' variable is not present. I think it is logical because it is a separate block, but how can I solve this then? Do you have any tip?

Thanks!


The problem is the columnToShow variable is out of scope. It means nothing at that point. Instead try $(this).fadeIn("slow").

The $(this) refers to the element that you have just faded as the callback function is attached to that element.

EDIT: (misread the question)

If you change it something like the following it should work.

function hideColumnAndShowOther(columnToHide, columnToShow) {
    var showColumn = columnToShow;
    $(columnToHide).fadeTo("slow", 0.0,
        function() {
           $(showColumn).fadeIn("slow");
        });
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜