悬停时的CSS动画 - 完成后暂停

标签 css css-animations

我在图像上有一个 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 在悬停时改变其位置并停留在那里。 谢谢

最佳答案

您可以使用 houvecss 来更新 div 的位置,就像这个示例一样

.uael-post__content-wrap:hover{
  //do what ever you want 
}

关于悬停时的CSS动画 - 完成后暂停,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53617160/

相关文章:

javascript - 组合 jQuery 同位素过滤器

asp.net - 无法防止 CheckBoxList 控件溢出

css - 为什么 CSS3 动画不起作用?

css - 如何转换宽度为 : auto? 的内容宽度

css - 仅将线性渐变动画应用于网格/网格叠加层

html - 如何让我的关键帧动画顺利开始?

html - 悬停 css 时背景颜色不变

html - 引导除第一个元素外的 4 个中心元素

html - 垂直滚动 div 内的水平滚动 div

html - 如何创建淡入/淡出图像动画