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

标签 javascript jquery html css animation

昨天我在将鼠标悬停在另一个链接上时让图像淡入方面得到了一些帮助,但我很难弄清楚如何让它淡出。这可能涉及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;
}

Example Fiddle

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

关于javascript - 将鼠标悬停在文本上,图像淡入淡出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28369962/

相关文章:

javascript - jQuery 如何让 $(this) 选择器触发多个类

javascript - 如何使用 jQuery 从输入类型文件中获取选定的文件名和文件路径

javascript - 按最接近已发生和将要发生的日期排序

jquery - 来自 jQuery get 的 JSON 响应引发 "Invalid label"

jquery - 将 Google Analytics 事件添加到导航项

javascript - 如何将数据从新窗口传递到父窗口

javascript - 在 NodeJS 中,如何从虚拟函数中退出父函数

javascript - 使用 jquery 创建新 DOM 时无法读取 if 语句

html - 网站不滚动

html - 将绘图保存为 html