繁体   English   中英

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

[英]Hover Over Text, Image Fades In & Out

我昨天得到了一些帮助,当一个图像在另一个链接上空盘旋时,图像会淡入,但我很难弄清楚如何让它淡出。 这可能涉及java? 我很抱歉,因为我是更高级的编码(过去的基本CSS / HTML)的新手。

这是昨天有人给我的东西,它很好地消失了,但是当你从链接中移除鼠标时,它就像淡出一样。

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;
}

示例小提琴

请注意,我加速了小提琴中的过渡,因为在我的经验中,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> 

暂无
暂无

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

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