简体   繁体   English

使用jquery画廊将图像放在悬停的另一图像上

[英]Putting an image over another image on hover with jquery for a gallery

I have a gallery and I want to overlay each image on hover with a transparent image that has a zoom icon. 我有一个图库,我想用具有缩放图标的透明图像在悬停时覆盖每个图像。 How can I accomplish this in the most efficient way with jQuery? 如何使用jQuery以最有效的方式完成此任务? All gallery images are in an <a></a> tag like below: 所有图库图像都在<a></a>标记中,如下所示:

<a href="pictures/gallery/fullHD/1.jpg" target="_blank">
    <img src="pictures/gallery/fullHD/1.jpg" class="gallery_pic"/>
</a> 

I looked for answers but I couldn't find any that resolve my problem. 我在寻找答案,但找不到任何能解决我问题的方法。 If you know a way to accomplish this without jQuery that would be fine too. 如果您知道一种无需jQuery即可完成此操作的方法,那也很好。

There's no jQuery needed here - you can use CSS alone to achieve what you require. 这里不需要jQuery-您可以单独使用CSS来实现所需的功能。 You can use the :before pseudo class to add content to the a element which is shown on :hover . 您可以使用:before伪类将内容添加到显示在:hovera元素上。 Try this: 尝试这个:

a:before {
    position: absolute;
    font:normal normal normal 14px/1 FontAwesome;
    content: "\f002";
    top: 5px;
    left: 5px;
    width: 50px;
    height: 50px;
    opacity: 0;
    -webkit-transition: opacity 0.5s;
    -moz-transition: opacity 0.5s;
    transition: opacity 0.5s;
}
a:hover:before {
    opacity: 1;
}

Example fiddle 小提琴的例子

Note that I used FontAwesome to add a magnifying glass icon, but you could just as easily use any image you need and set the background-image property instead. 请注意,我使用FontAwesome添加了一个放大镜图标,但是您可以轻松使用所需的任何图像并设置background-image属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM