2010-11-27 115 views
0

我有下面的代码片段:jQuery - fadeOut回调函数不工作?

$(".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功能。如果我在函数中使用这些语句并将它们放在函数之后,这将起作用;但它不能像现在这样工作。我有一个标题列表(目前它们只是一组卡片的产品代码,但它们将陈述出现在卡片上的实际标题),并点击其中一个我希望图像淡出,更改为一个被选中并淡入。然而,正如我所说的,这只有在我将这些语句放在函数之外时才有效。这意味着用户在淡出之前突然看到图像变化,这并不令人满意。

任何人都可以看到有什么不对吗?如果有人想让我检查课程名称等,请重新阅读这个问题,你会发现它确实与回调函数外的语句一起工作!

在此先感谢。

问候,

理查德

回答

2

尝试:

$(".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); 
     } 
    ); 
}); 
+0

当然...`$(本)`的`fadeOut`功能改变,要么或`$(本) `在回调函数中不可访问(不知道为什么这会是`$ this`可访问的)。谢谢!当我能够时,将会标记为答案。 – ClarkeyBoy 2010-11-27 05:37:40