将鼠标悬停在文本上,图像淡入淡出

Hover Over Text, Image Fades In & Out

昨天我在将鼠标悬停在另一个图像上时让图像淡入方面得到了一些帮助 link,但我很难弄清楚如何让它淡出。这可能涉及java?我很抱歉,因为我对更高级的编码(过去的基本 CSS/HTML)还很陌生。

这是昨天有人给我的东西,它很好地淡入,但我希望它在你从 link.

上移开鼠标后淡出
img { opacity: 0; }
a:hover +img {
    -webkit-animation: changeOpacity 5s;
    animation: changeOpacity 5s;
}
@-webkit-keyframes changeOpacity {
    0%   { opacity: 0; }    
    100% { opacity: 1; }
}

/* Standard syntax */
@keyframes changeOpacity {
    0%   { opacity: 0; }    
    100% { opacity: 1; }
}

这是 HTML:

<a href="http://lorempixel.com/300/300/sports/1">
    Hover the see Full image,click to go there
</a>
<img src="http://lorempixel.com/300/300/sports/1" width="200" height="200" />
<br>
<a href="http://lorempixel.com/300/300/sports/1">
    Hover the see Full image,click to go there
</a>
<img src="http://lorempixel.com/300/300/sports/1" width="200" height="200" />

如有任何帮助,我们将不胜感激!

关键帧在这里是大材小用。您可以简单地使用 transition 然后根据需要更改 opacity 值:

img { 
    opacity: 0; 
    transition: opacity 5s;
}
a:hover +img {
    opacity: 1;
}

Example Fiddle

请注意,我在 Fiddle 中加快了过渡,因为根据我的经验,5 秒对于淡入效果来说有点过长。

这是我的做法:(运行 直接在下面)

$('a').hover( function(){
    $(this).parent().find('img').css('opacity',1)
}, function(){
    $(this).parent().find('img').css('opacity',0)
});
img{
    opacity : 0;
  transition: opacity 1s ease-in-out;
   -moz-transition: opacity 1s ease-in-out;
   -webkit-transition: opacity 1s ease-in-out;
    
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div>
    <a href="http://lorempixel.com/300/300/sports/1">Hover the see Full image,click to go there</a>        <br>
    <img src="http://lorempixel.com/300/300/sports/1" width="200" height="200" />
</div>
    
<div>   
<a href="http://lorempixel.com/300/300/sports/1">Hover the see Full image,click to go there</a><br>
<img src="http://lorempixel.com/300/300/sports/1" width="200" height="200" />
</div>