2014-12-03 55 views
1

我试图在页面加载时实现所有<div>效果。如何使用jQuery添加悬停类

jQuery('.postCenter').addClass("hiddenClass").viewportChecker({ 
     classToAdd: 'visibleClass animated bounce', 
     offset: 200 
     }); 

现在页面加载时,这是唯一的工作。我需要相同的效果,当我通过鼠标悬停鼠标<div>

我试过这个,但没有奏效。

$('.nom-img').hover(function(){ 

    $('.tag-nom').removeClass('animated'); 
    $('.tag-nom').removeClass('bounce'); 

    $('.tag-nom').addClass('animated'); 
    $('.tag-nom').addClass('bounce'); 
}); 

我的标记是这样的:

<div class="col-md-4 col-sm-4 col-xs-12 postLeft"> 
    <h2>Topeka, Kansas</h2> 
    <div class="nom-img"> 
    <a href="topeka.html"><img src="img/xxxxxx"></a> 
    </div> 
    <div class="tag-nom postCenter"> <a href="#"><img src="XXX"></a> 
     <h4><a href="#">vsdvsdvsdvsdv</a></h4> 
    </div> 
</div> 

我想tag-nom当我将鼠标悬停在div nom-img

我有这样的列6动画。所以只有对应的tag-nom应该悬停在动画上。我怎样才能做到这一点?

+1

你必须使用什么是$(本)选择,而不是类选择中添加的悬停功能。 – Andi 2014-12-03 14:40:41

回答

3

您需要修改悬停功能以接受两种方法,即:分别为mouseenter和mouseleave。您还需要针对.tag-nom是悬停元素的下一个同级元素:

$('.nom-img').hover(function(){ 
    $('.tag-nom').not($(this).next()).removeClass('animated bounce') 
    $(this).next().addClass('animated bounce'); 
},function(){ 
    $(this).next().removeClass('animated bounce'); 
}); 
+1

感谢它的工作:) – user1012181 2014-12-03 14:46:35

+1

@ user1012181:请标记答案,如果它帮助你,它会帮助别人知道whcih是最有用的答案 – BNN 2014-12-03 14:58:00

+0

@Milind Anantwar,在第一次悬停时,此操作不起作用。当我再次悬停时,它可以工作。当我向下滚动并上升时,即使没有悬停,效果也会再次显示。可能是什么问题? – user1012181 2014-12-05 15:46:42

0

试试这个:

$('.nom-img').hover(function(){ 

    $('.tag-nom').addClass('animated').addClass('bounce'); 
}, function(){ 

    $('.tag-nom').removeClass('animated').removeClass('bounce'); 
});