[英]Move the same image according to the button I hover over
I have 8 buttons (images) on the page, all in the same line. 我在页面上有8个按钮(图像),全部在同一行。 And one hidden image(red rectangular box) with no text on it. 还有一个隐藏的图像(红色矩形框),上面没有文字。 I want to display the same red box just below the button(image) I hover over with dynamic text on the image(which would be according to the link of the button) 我想在按钮(图像)下方显示相同的红色框我将鼠标悬停在图像上的动态文本上(根据按钮的链接)
HTML Code: HTML代码:
<div id="imageRings">
<img id="ringOne" class="rotate" src="images/ring1.png">
<img id="ringTwo" class="rotate" src="images/ring2.png">
<img id="ringThree" class="rotate" src="images/ring3.png">
<img id="ringFour" class="rotate" src="images/ring4.png">
<img id="ringFive" class="rotate" src="images/ring5.png">
<img id="ringSix" class="rotate" src="images/ring6.png">
<img id="ringSeven" class="rotate" src="images/ring7.png">
<img id="ringEight" class="rotate" src="images/ring8.png">
</div>
So these are the images on which when I hover I want an image to appear just below the respective image I hover over, and text on it depending on the link(i mean i should be able to modify the text displayed on the rectangular box) 所以这些是我悬停的图像,我希望图像显示在相应图像的下方,我将鼠标悬停在上面,并根据链接显示文字(我的意思是我应该可以修改矩形框上显示的文字)
I know I haven't given much code to begin with but I dont know what else to provide. 我知道我没有提供太多的代码,但我不知道还能提供什么。 All I am missing from the above code is the code of rectangular box image, but I havent written it anywhere as the position is what needs to determined and changed according to the hovering. 我在上面的代码中缺少的是矩形框图像的代码,但我没有把它写在任何地方,因为位置是需要根据悬停确定和改变的。
Try this; 尝试这个; place your images in an inline <li>
, then you can append that .rect div to each one on hover. 将您的图像放在内联<li>
,然后您可以在悬停时将.rect div附加到每个。 Here's a jsFiddle for an example as well. 这里也是一个jsFiddle例子。
HTML HTML
<ul id="imageRings">
<li><img class="rotate" src="images/ring1.png"></li>
<li><img class="rotate" src="images/ring2.png"></li>
<li><img class="rotate" src="images/ring3.png"></li>
<li><img class="rotate" src="images/ring4.png"></li>
<li><img class="rotate" src="images/ring5.png"></li>
<li><img class="rotate" src="images/ring6.png"></li>
<li><img class="rotate" src="images/ring7.png"></li>
<li><img class="rotate" src="images/ring8.png"></li>
</ul>
<div class="rect"></div>
jQuery jQuery的
$('imageRings img').on({
mouseenter: function() {
$(this).closest('li').append($('.rect'));
$('.rect').show();
},
mouseleave: function() {
$('.rect').hide()
}
});
CSS CSS
#imageRings li{display:inline-block;}
.rect{border:1px solid red;background:#a55;height:20px;display:none;}
Put your images in divisions and/or lists as follows 将图像放在分区和/或列表中,如下所示
<div id="hover">
<div class="ima 1">
<img src="your_img_1" />
<div class="fill">
</div></div>
<div class="ima 3">
<img src="your_img_2" />
<div class="fill">
</div></div>
<div class="ima 2">
<img src="your_img_3" />
<div class="fill">
</div>
</div></div>
Position as 位置为
.ima{
float:left /*Float to make parallel*/
}
img{
display:block;
}
Jquery: jQuery的:
$('.ima img').hover(function(){
$(this).parent().find('.fill').html('<img src="image" />');
},
function(){
$(this).parent().find('.fill').html(' ');
}
);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.