代码之家  ›  专栏  ›  技术社区  ›  ClarkeyBoy

jquery-fadeout回调函数不工作?

  •  0
  • ClarkeyBoy  · 技术社区  · 14 年前

    我有以下代码片段:

    $(".caption").click(function () {
        var enlargementDiv = $(this).closest(".image-enlargement");
        enlargementDiv = enlargementDiv.find("div.enlargement");
        enlargementDiv.fadeOut(500, 
           function () {
               enlargementDiv.html($(this).find("div").html()); enlargementDiv.fadeIn(500);
           }
        );
    });
    

    这基于window.load函数。如果我将语句放在函数中并放在函数之后,这是有效的;但是它不能像现在这样工作。我有一个标题列表(目前它们只是一组卡片的产品代码,但它们将说明卡片上显示的实际标题),单击其中一个,我希望图像淡出,切换到选中的并淡入。但是,正如我所说,只有当我将语句放在函数之外时,这才有效。这意味着用户看到图像在淡出之前突然发生了变化,这并不令人满意。

    有人看到这个有什么问题吗?如果有人想让我检查类名等,请重新阅读这个问题,你会看到的。 使用回调函数之外的语句!!

    事先谢谢。

    当做,

    理查德

    1 回复  |  直到 14 年前
        1
  •  2
  •   sje397    14 年前

    $(".caption").click(function () {
        var $this = $(this);
        var enlargementDiv = $this.closest(".image-enlargement");
        enlargementDiv = enlargementDiv.find("div.enlargement");
        enlargementDiv.fadeOut(500, 
           function () {
               enlargementDiv.html($this.find("div").html()); enlargementDiv.fadeIn(500);
           }
        );
    });