简单的Jquery悬停问题

时间:2011-01-27 22:32:31

标签: jquery css hover

我有一些非常简单的jquery,如下所示:

$(".block").hover(function(){
    $(".drag").stop().fadeIn(1000);                
}, function(){
    $(".drag").stop().fadeOut(1000);
});

我有一系列div,每个div都有一个block类。当我将鼠标悬停在.block上时,.drag会使用一类块在所有div中淡入淡出。我只想让.drag在鼠标悬停的元素上淡入,而不是全部。谢谢!

2 个答案:

答案 0 :(得分:2)

假设您想要的.drag元素是悬停在元素上的元素的后代:

$(".block").hover(function(){
    $(this).find(".drag").stop().fadeIn(1000);                
}, function(){
    $(this).find(".drag").stop().fadeOut(1000);
});

答案 1 :(得分:1)

如何使用委托?

你不能使用悬停,你需要mousein和mouseout JQuery API -> Delegate()。 API文档特别提到了悬停事件。

 // something more specific than body would probably be good, but some 
 // common parent of these divs
 $('body').delegate('.block', 'mousein', function() {
     $(this).find(".drag").stop().fadeIn(1000); 
 });

 $('body').delegate('.block', 'mouseout', function() {
     $(this).find(".drag").stop().fadeOut(1000);
 });
相关问题