gpt4 book ai didi

html - 使用 css 动画应用悬停缓动效果

转载 作者:行者123 更新时间:2023-11-28 12:42:30 25 4
gpt4 key购买 nike

在此LIVE DEMO您可以看到每个 div 中的动画如何移动其图像并将 opacity:1 赋予文本。

当 hover-off 时,所有样式自然会直接回到初始状态,但我希望它们能够顺利(轻松)地完成,而不是同时设置所有初始样式而没有任何进展。

这里是相关的动画代码:

#highlights div[class*="high-"]:hover > p {
-webkit-animation:downOp 0.3s ease-in 0s forwards;
-ms-animation:downOp 0.3s ease-in 0s forwards;
animation:downOp 0.3s ease-in 0s forwards;
}
#highlights div[class*="high-"]:hover > .image {
-webkit-animation:imgTrans 5s ease-out 0s forwards;
-ms-animation:imgTrans 5s ease-out 0s forwards;
animation:imgTrans 5s ease-out 0s forwards;
}
@-webkit-keyframes downOp {
0% {
opacity:0.7;
}
100% {
opacity:1;
}
}
@-ms-keyframes downOp {
0% {
opacity:0.7;
}
100% {
opacity:1;
}
}
@keyframes downOp {
0% {
opacity:0.7;
}
100% {
opacity:1;
}
}
@-webkit-keyframes imgTrans {
0% {
margin-right: 0;
}
100% {
margin-right: -50px;
}
}
@-ms-keyframes imgTrans {
0% {
margin-right: 0;
}
100% {
margin-right: -50px;
}
}
@keyframes imgTrans {
0% {
margin-right: 0;
}
100% {
margin-right: -50px;

}

最佳答案

使用 css transform 而不是 css animation!它会自动处理悬停效果!

html

<article id="highlights">
<div class="high-rinoplastia">
<div class="image"></div>
<p><strong>Rinoplastia</strong>

<br> <span>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod</span>

</p>
</div>
</article>

CSS

    #highlights {
min-height: 525px;
width: 1170px;
margin:0 auto;
}
#highlights div[class*="high-"] {
border: 1px solid rgba(0, 0, 0, 0.28);
display: inline-block;
float: left;
height: 150px;
margin: 10px;
position: relative;
width: calc(33% - 20px);
overflow: hidden;
}
#highlights .image {
height:100%;
transition:all 4s ease;
}
#highlights p {
background-color: white;
bottom: 0;
height: 60px;
margin-bottom: 0px;
position: absolute;
opacity:0.7;
transition:all 0.6s ease;
}
#highlights span {
display: block;
font-size: 12px;
margin: 2px;
}
#highlights:hover p {
opacity:1;
}
#highlights:hover .image {
transform:all 5s ease;
margin-right: -50px;
}
#highlights .high-rinoplastia .image {
background: url(http://mypet.guru/wp-content/uploads/2014/06/fluffy-cats-009.jpg) no-repeat right center;
}
#highlights .high-venas .image {
background: url(http://mypet.guru/wp-content/uploads/2014/06/fluffy-cats-009.jpg) no-repeat right center;
}
#highlights .high-cirugiaCalvicie .image {
background: url(http://mypet.guru/wp-content/uploads/2014/06/fluffy-cats-009.jpg) no-repeat right center;
}
#highlights .high-tratamientoCalvicie .image {
background: url(http://mypet.guru/wp-content/uploads/2014/06/fluffy-cats-009.jpg) no-repeat right center;
}

关于html - 使用 css 动画应用悬停缓动效果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26176713/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com