简体   繁体   English

在鼠标悬停时在图像中心显示图标字体

[英]Show icon font on image center on mouse hover

I´m trying to do an effect and show a search icon font when the mouse hover my "image1.png". 当鼠标悬停我的“ image1.png”时,我试图产生一种效果并显示搜索图标字体。 I already did the effect with jQuery but now I do not see how I can integrate the iconic font with jquery. 我已经用jQuery实现了效果,但是现在看不到如何将标志性字体与jquery集成在一起。 Has anyone done something like that? 有人做过类似的事情吗? Can you give a little help? 你能帮一点忙吗?

 <article id="loop-news">
     <span id="testIcon"><I  class = "fa fa-search-plus" >  <!--show just on mouse hover -->
     <img src="image1.png" id="test" />
     <h2>Title </h2>
     <p>My Post</p>
 </article>  

My css to hide icon font at first: 首先我要隐藏图标字体的css:

#testIcon>i{display:none;}

My jquery to give an opacity effect: 我的jQuery给不透明效果:

 $("#test").hover(function() {
     $(this).animate({opacity: 0.5}, 500);
 }, function() {
     $(this).animate({opacity: 1.0}, 500);
 });

I would use CSS3 transitions if I understand your issue. 如果我了解您的问题,我会使用CSS3过渡。 In this example, I would just replace the font-family with your icon font (assuming that's how it works - never used it). 在此示例中,我将用您的图标字体替换字体系列(假设这就是它的工作方式-从未使用过)。

h2 {
    position: aboslute;
    margin-top: -350px;
    display: none;
    text-align: center;
    font-family: arial;
}
#loop-news:hover h2 {
    display: block;
}
#loop-news:hover img {
    opacity: .5;
}
img, h2 {
    -webkit-transition: all .8s ease;
    -moz-transition: all .8s ease;
    -ms-transition: all .8s ease;
    -o-transition: all .8s ease;
    transition: all .8s ease;
}

JS Fiddle JS小提琴

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

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