三张图像,使用 jQuery 将鼠标悬停在动画上
我有三个图像,在悬停时,每个图像都需要在它们下方显示一个单独的动画图像。下面的代码适用于其中之一,但它显示相同的图像三次并调用相同的悬停图像。
您认为使每个图像成为三个独立图像的最佳方式是什么?
CSS
.menu2 {
padding: 0;
list-style: none;
}
.menu2 li {
float: left;
position: relative;
}
.menu2 a {
display: block;
width: 218px;
height:181px;
background: url(images/btn_off.png) no-repeat center center;
}
.menu2 li em {
background: url(images/btn_txt.png) no-repeat;
width: 218px;
height: 88px;
position: absolute;
top:200px;
left: 0;
z-index: 2;
display: none;
}
jQuery
$(document).ready(function(){
$(".menu2 a").hover(function() {
$(this).next("em").animate({opacity: "show", top: "180"}, "slow");
}, function() {
$(this).next("em").animate({opacity: "hide", top: "200"}, "fast");
});
});
HTML
<ul class="menu2">
<li>
<a href="#"></a>
<em></em>
</li>
<li>
<a href="#"></a>
<em></em>
</li>
<li>
<a href="#"></a>
<em></em>
</li>
</ul>
I have three images that, on hover, need to each show a separate image animated underdeath them. The code below works for one of them but it shows the same image three times and invokes the same hover image as well.
What do you think is the best way to make each of the images animate three separate images?
CSS
.menu2 {
padding: 0;
list-style: none;
}
.menu2 li {
float: left;
position: relative;
}
.menu2 a {
display: block;
width: 218px;
height:181px;
background: url(images/btn_off.png) no-repeat center center;
}
.menu2 li em {
background: url(images/btn_txt.png) no-repeat;
width: 218px;
height: 88px;
position: absolute;
top:200px;
left: 0;
z-index: 2;
display: none;
}
jQuery
$(document).ready(function(){
$(".menu2 a").hover(function() {
$(this).next("em").animate({opacity: "show", top: "180"}, "slow");
}, function() {
$(this).next("em").animate({opacity: "hide", top: "200"}, "fast");
});
});
HTML
<ul class="menu2">
<li>
<a href="#"></a>
<em></em>
</li>
<li>
<a href="#"></a>
<em></em>
</li>
<li>
<a href="#"></a>
<em></em>
</li>
</ul>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以扩展
.menu2 li em
类以针对所需的不同图像提供三种变体,也可以保持其广泛性并在样式标记中显式指定background
属性。您还可以使用 jQuery 来修改图像,但这会增加对脚本工作的依赖性。(假设它是您要更改的
背景
属性)You can either expand your
.menu2 li em
class to have three variations for the different images you want, or keep it broad and explicitly specify thebackground
attribute in the style tag. You could also use jQuery to modify the image, but this adds a dependency on the script to work.(this is assuming it's the
background
attribute you're looking to alter)