试图使不同的文字出现在3个对齐的图像在悬停
Trying to make different text appear below 3 aligned images on hover
首先,这是我的例子:https://jsfiddle.net/y532ouzj/33/
HTML: <div id="image" class="item">
<a ><img src="http://www.topring.com/images/carre_download_cat_ENG.jpg"></a>
</div>
<div id="text" class="show">Text 1</div>
<div id="image" class="item">
<a ><img src="http://www.topring.com/images/carre_download_cat_ENG.jpg"></a>
</div>
<div id="text" class="show">Text 2</div>
<div id="image" class="item">
<a ><img src="http://www.topring.com/images/carre_download_cat_ENG.jpg"></a>
</div>
<div id="text" class="show">Text 3</div>
CSS: .item {
/* To correctly align image, regardless of content height: */
vertical-align: top;
display: inline-block;
/* To horizontally center images and caption */
text-align: center;
/* The width of the container also implies margin around the images. */
width: 190px;
}
.show {
display: none;
}
.item:hover + .show {
display: block;
}
JAVASCRIPT:
$('#image').hover(function() {
$('#text').show();
}, function() {
$('#text').hide();
});
它几乎工作,但我一定是忘记了一点东西,因为我的3张照片没有呆在我想要的地方,一旦我开始鼠标悬停。所以如果你不悬停在图片上,一切都很好,3张图片对齐。把鼠标悬停在图片1或2上,文字正好在我想要的地方,但是为什么我的图片3和图片2也往下移动?悬停在图片#3上,一切都按照它应该的方式工作。
你有很多问题。首先,id只能使用一次。将它们更改为类,应该就没问题了。其次,将div移动到图像div的内部,它将只显示您想要显示的内容。更新后的javascript和html如下:
小提琴:https://jsfiddle.net/y532ouzj/34/