这是结构:
<div class="features-image">
</div>
<div class="features-image">
</div>
<div class="features-image">
</div>
我制作了一个 jQuery 函数,如果特征图像处于悬停状态,就会发生一些事情。
我的问题是我有 3 个特色图片,当我的鼠标悬停在第一个特色图片上时,第二个和第三个也会得到相同的效果。
我希望如果第一个特征图像处于悬停状态,则第二个和第三个不会复制第一个图像的效果。
代码:
jQuery(document).ready(function() {
jQuery('.features-image').hover(function(){
jQuery(this).animate({
top:'95px',
height:'135px'
},500);
},function(){
jQuery('.features-content').animate({
top:'170px',
height:'60px'
},500);
});
});
最佳答案
当你定义像悬停这样的东西时,你使用 this 来引用当前元素 -
$('.features-image').hover(function() {
$(this) // mouseover do stuff
}, function {
$(this) // mouseout do stuff
});
关于jquery - 如何在具有相同类名的多个类中选择 1 个类?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14967787/