Jquery 元素不';你不能回到原来的位置吗?
我有一个底部为10的元素。我希望它在上面悬停时变为20。鼠标悬停时返回到10:Jquery 元素不';你不能回到原来的位置吗?,jquery,Jquery,我有一个底部为10的元素。我希望它在上面悬停时变为20。鼠标悬停时返回到10: $('.home-box-caption a').hover(function() { $('.home-box-caption a').animate({ bottom: 20 }, 200, function() { bottom: 10 }); }); 现在只剩下20分钟了 我做错了什么?您没有正确使用.hover() .hover(函数[,函数]) 考虑使用this关键字(除非您
$('.home-box-caption a').hover(function() {
$('.home-box-caption a').animate({
bottom: 20
}, 200, function() {
bottom: 10
});
});
现在只剩下20分钟了
我做错了什么?您没有正确使用
.hover()
.hover(函数[,函数])
考虑使用this
关键字(除非您的目的是为.home box caption
下的所有a
元素设置动画),或者将这些元素存储在变量中,这样您就不必每次都重新查询DOM
阅读更多信息:您可能希望使用hover的第二个参数(如下所示)在mouseout上设置元素的动画
$('.home-box-caption a').hover(function () {
$(this).animate({
bottom: 20
}, 200)
}, function () {
$(this).animate({
bottom: 10
}, 200)
});
您应该将第二个动画作为
hover
的第二个参数:
$('.home-box-caption a').hover(
function(){
//this is invoked when the mouse ENTERS the element
$(this).animate({top: 140}, 200);
},
function(){
//this is invoked when the mouse LEAVES the element
$(this).animate({top: 150}, 200);
}
);
()
hover
方法支持回调:.hover(handlerIn(eventObject)、handlerOut(eventObject))
。看
第一个将在鼠标进入元素时调用,第二个将在鼠标离开元素时调用
animate
方法还支持回调:.animate(properties[,duration][,easing][,complete])
但是当第一个动画完成时,将调用此complete
回调。哦,是的,我只是想给水流设置动画element@alexchenco-我已使用$(this)
$('.home-box-caption a').hover(
function(){
//this is invoked when the mouse ENTERS the element
$(this).animate({top: 140}, 200);
},
function(){
//this is invoked when the mouse LEAVES the element
$(this).animate({top: 150}, 200);
}
);