[英]Is it possible to make jQuery only target div for hover animation if it is a child of the element being hovered over?
[英]Animation only for hovered element
尝试用我的帖子信息做一些技巧。 当我将鼠标悬停在一个元素上时,所有元素都变为活动状态。
如何只将动画制作到悬停的元素上? 试过了:
$('.post-pic-holder').find('.post-info').hover(function(){
$(this).animate({bottom:'0'},200);
},function(){
$(this).animate({bottom:'-30px'},200);
});
您需要定位特定的后代,例如:
$(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);
});
});
仅供参考,jQuery hover
方法接受输入/输出处理程序:
$('.post-pic-holder').hover(function (e) {
$(this).find('.post-info').animate({
bottom: e.type === "mouseenter" ? 0 : -30
}, 200);
});
但是只能在支持CSS3过渡的浏览器的CSS中完成:
.post-info {
transition: bottom 200ms;
}
.post-pic-holder:hover .post-info {
bottom: 0;
}
尝试这个:
$(document).ready(function(){
$('.post-pic-holder').hover(function(){
$(this).first().animate({bottom:'0'},200);
},function(){
$(this).first().animate({bottom:'-30px'},200);
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.