html - 悬停离开后CSS没有平滑淡入
问题描述
我试图让这个图像在悬停离开后平滑地淡入,但它似乎只是弹回,我希望过渡看起来平滑并在淡出时混合在一起,就像它在淡出时一样。
我可能对 css 太过分了,但我的主要目标是让第一个 div 成为图像,第二个 div 成为带有信息的背景。
.imageInfo {
display: block;
position: absolute;
bottom: 5px;
left: 15px;
color: black;
font-style: italic !important;
font-size: smaller;
}
.imageContainer {
position: relative;
display: inline-block;
vertical-align: middle;
margin-left: 15px;
margin-bottom: 20px;
min-width: 330px;
height: 150px;
}
.cImage {
max-width: 400px;
min-height: 130px;
width: 100%;
height: 100%;
padding: 5px;
vertical-align: middle;
}
imageContainer.img {
width: auto;
display: inline-block;
}
.imageContainer img.play,
.imageContainer img.picture,
.imageContainer img.fade {
width: 100%;
height: 100%;
position: absolute;
top: 0;
left: 0;
transition: ease-in-out 0.6s;
}
.imageContainer img.play {
opacity: 1;
visibility: visible;
}
.imageContainer:hover img.play {
opacity: 0;
visibility: hidden;
}
.imageContainer div.picture {
opacity: 0;
visibility: hidden;
}
.gradient {
background-image: linear-gradient(to top, orange, red);
}
.imageContainer div.picture .fade {
opacity: 0;
visibility: hidden;
}
.imageContainer:hover div.picture {
opacity: 1;
visibility: visible;
}
.imageContainer:hover div.picture .fade {
opacity: 1;
visibility: visible;
}
<span class="imageContainer">
<img [src]="https://www.w3schools.com/images/w3schools_green.jpg"
class="play cImage">
<div class="picture cImage gradient">
<a class="fade">Baby Yoda</a>
<div class="imageInfo fade">
<strong>Date:</strong><span>"01/01/1999"</span>
</div>
</div>
</span>
解决方案
使用src
而不是[src]
. 更改<img [src]="https://www.w3schools.com/images/w3schools_green.jpg" class="play cImage" />
为<img src="https://www.w3schools.com/images/w3schools_green.jpg" class="play cImage" />
.imageInfo {
display: block;
position: absolute;
bottom: 5px;
left: 15px;
color: black;
font-style: italic !important;
font-size: smaller;
}
.imageContainer {
position: relative;
display: inline-block;
vertical-align: middle;
margin-left: 15px;
margin-bottom: 20px;
min-width: 330px;
height: 150px;
}
.cImage {
max-width: 400px;
min-height: 130px;
width: 100%;
height: 100%;
padding: 5px;
vertical-align: middle;
}
imageContainer.img {
width: auto;
display: inline-block;
}
.imageContainer img.play,
.imageContainer img.picture,
.imageContainer img.fade {
width: 100%;
height: 100%;
position: absolute;
top: 0;
left: 0;
transition: opacity 0.6s linear, visibility 0.6s linear;
}
.imageContainer img.play {
opacity: 1;
visibility: visible;
transition: opacity 0.6s linear, visibility 0.6s linear;
}
.imageContainer:hover img.play {
opacity: 0;
visibility: hidden;
transition: opacity 0.6s linear, visibility 0.6s linear;
}
.imageContainer div.picture {
opacity: 0;
visibility: hidden;
transition: opacity 0.6s linear, visibility 0.6s linear;
}
.gradient {
background-image: linear-gradient(to top, orange, red);
}
.imageContainer div.picture .fade {
opacity: 0;
visibility: hidden;
transition: opacity 0.6s linear, visibility 0.6s linear;
}
.imageContainer:hover div.picture {
opacity: 1;
visibility: visible;
transition: opacity 0.6s linear, visibility 0.6s linear;
}
.imageContainer:hover div.picture .fade {
opacity: 1;
visibility: visible;
transition: opacity 0.6s linear, visibility 0.6s linear;
}
<span class="imageContainer">
<img src="https://www.w3schools.com/images/w3schools_green.jpg" class="play cImage">
<div class="picture cImage gradient">
<a class="fade">Baby Yoda</a>
<div class="imageInfo fade">
<strong>Date:</strong><span>"01/01/1999"</span>
</div>
</div>
</span>
在您的评论之后,如果我理解正确,那么您想要相同的过渡效果on mouse in
和on mouse leave
. 然后transition-timing-function
将linear
代替easy-in-out | easy-in | ease-out
等。您必须阅读有关transition-timing-function 的更多信息。而且你必须分开transition-propery
(opacity
,visibility
)。您必须阅读有关transition-property 的更多信息。
:hover
您只为or编写了转换mouse in
。现在你必须为mouse leave
. 你CSS
会是这样的。
.imageContainer img.play{
opacity: 1;
visibility: visible;
transition: opacity 0.6s linear, visibility 0.6s linear;
}
.imageContainer:hover img.play{
opacity: 0;
visibility: hidden;
transition: opacity 0.6s linear, visibility 0.6s linear;
}
检查上面的代码片段它正在工作mouse in
并且mouse out
.
推荐阅读
- kubernetes - 在 Helm File 下使用 Kubernetes Secret
- java - 如何在 imageview 中添加滑动手势?
- json - 我不知道如何使用对象映射器和 Alamofire 解析从 json 调用到我的 tableView 的数据
- security - WebHttpBinding 中的 WCF 数据加密
- reactjs - 简单的 ReactJS 分页
- python - 优化熊猫循环
- python - Python 正则表达式执行卡住了
- python - Python 删除 CSV 中的列并写入新的 CSV 文件
- java - MapBox 崩溃了
- css - Chrome 输入自动提示记忆值更改 CSS