简体   繁体   中英

Animation only for hovered element

Trying to do some trick with my post information. When I hover mouse on one element - all elements became active.

How can I made this animation only to hovered element? Tried it:

$('.post-pic-holder').find('.post-info').hover(function(){
 $(this).animate({bottom:'0'},200);
},function(){
 $(this).animate({bottom:'-30px'},200);
});

http://jsfiddle.net/fresa150/8ftnF/

You need to target specific descendant, eg:

$(document).ready(function(){
    $('.post-pic-holder').hover(function(){
        $(this).find('.post-info').animate({bottom:'0'},200);
    },function(){
        $(this).find('.post-info').animate({bottom:'-30px'},200);
    });
});

--DEMO--

FYI, jQuery hover method accepts in/out handler:

$('.post-pic-holder').hover(function (e) {
    $(this).find('.post-info').animate({
        bottom: e.type === "mouseenter" ? 0 : -30
    }, 200);
});

--DEMO--

But could be done only in CSS for browser which support CSS3 transition :

.post-info {    
    transition: bottom 200ms;
}
.post-pic-holder:hover .post-info {
    bottom: 0;    
}

--DEMO CSS--

Try this:

$(document).ready(function(){
  $('.post-pic-holder').hover(function(){
    $(this).first().animate({bottom:'0'},200);
      },function(){
    $(this).first().animate({bottom:'-30px'},200);
     });
 });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM