我在图像上有一个 div,我想用 css 动画将他的位置从图像的顶部更改到底部(通过悬停触发),并在动画后以他的新值留在底部(我尽量不使用 jQuery)。
所以现在我在鼠标悬停时运行动画,当鼠标悬停时则暂停。并且使用 animation-fill-mode: forwards 它可以工作,唯一的事情是我必须保持悬停才能完成动画。我的代码:
<div class="home-posts-section">
<div class="home-posts-top-content">
<img src="images/worldmap.jpg" >
<div class="uael-post__content-wrap">
<h1>some content</h1>
<p>some more content</p>
</div>
</div>
</div>
.home-posts-top-content{
width:400px;
height:400px;
position:relative;
z-index:1;
}
.home-posts-top-content img{
width:100%;
height:100%;
}
.uael-post__content-wrap{
width:90%;
margin:0 auto;
;
background-color: rgba(255,255,255,0.9);
position:absolute;
top:25px;
}
.home-posts-section .home-posts-top-content .uael-post__content-wrap{
-webkit-animation: scroll_to_bottom 2s; /* Safari, Chrome and Opera > 12.1 */
-moz-animation: scroll_to_bottom 2s; /* Firefox < 16 */
-ms-animation: scroll_to_bottom 2s; /* Internet Explorer */
-o-animation: scroll_to_bottom 2s; /* Opera < 12.1 */
animation: scroll_to_bottom 2s;
-webkit-animation-play-state:paused;
-webkit-animation-fill-mode: forwards;
}
.home-posts-section .home-posts-top-content .uael-post__content-wrap:hover{
-webkit-animation-play-state:running;
}
@keyframes scroll_to_top {
from { top: 258px; }
to { top: 25px; }
}
/* Firefox < 16 */
@-moz-keyframes scroll_to_top {
from { top: 258px; }
to { top: 25px; }
}
/* Safari, Chrome and Opera > 12.1 */
@-webkit-keyframes scroll_to_top {
from { top: 258px; }
to { top: 25px; }
}
我正在尝试找到一种方法,使 div 在悬停时改变其位置并停留在那里。 谢谢
最佳答案
您可以使用 houve
css 来更新 div 的位置,就像这个示例一样
.uael-post__content-wrap:hover{
//do what ever you want
}
关于悬停时的CSS动画 - 完成后暂停,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53617160/