css - 如何在启动另一个动画或访问另一个页面时不初始化 CSS3 动画?

标签 css css-transitions

我想知道如何避免关键帧动画在启动另一个动画或访问浏览器的另一个选项卡后自动重置。

@-webkit-keyframes play1 {
            0% {
              -webkit-transform: translate(0px,0);
            }
           50% {
              -webkit-transform: translate(-60px,0) rotate(-1080deg) scale(1.5);
           }
           100% { 
               -webkit-transform: translate(-120px,0) rotate(-2060deg) scale(1);
           }
        }
.play1 {         
    -webkit-animation-name: play1;
    -webkit-animation-duration: 2s;
    -webkit-animation-timing-function: linear;
    -webkit-animation-direction: alternate;
}

@-webkit-keyframes play2 {
    0% {
        -webkit-transform: translate(0px,0);
    }
    50% {
        -webkit-transform: translate(-60px,0) rotate(-1080deg) scale(3);
    }
    100% {
        -webkit-transform: translate(-120px,0) rotate(-2060deg) scale(1);
    }
}
.play2 {         
    -webkit-animation-name: play2;
    -webkit-animation-duration: 2s;
    -webkit-animation-timing-function: linear;
    -webkit-animation-direction: alternate;
}

在这个例子中,如果我启动动画 play1 然后 play2 通过在元素上添加相应的类,元素的位置根据 play1 动画会自动重置到它的初始位置(如果我访问另一个选项卡并返回,我所有的元素都在它们的初始位置),如何避免这种情况?

在 mozilla 上更糟糕的是,动画结束后会重置。 通过使用 animation-iteration-count: infinite; 属性,我没有这种行为,但我只想播放一次。

最佳答案

启用此功能的属性是:animation-fill-mode: forwards

关于css - 如何在启动另一个动画或访问另一个页面时不初始化 CSS3 动画?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17467778/

相关文章:

html - Safari 不渲染 css 渐变文本

css - 如何在动态高度的 flexbox 中进行 div 拉伸(stretch)?

jQuery 计数类为 "checked"的元素

javascript - Electron 没有在应用程序中完全更新已编辑的 index.html

css - 单独在背景图像上的 compass 过渡不透明度

html - 使用 z-index 将重叠的 css3 过渡带到前面

javascript - 使用 CSS 进行页面转换

css - 为什么使用 Arial、Helvetica、sans-serif 作为字体系列而不只是 sans-serif?

html - 如何在悬停时向右移动箭头?

wordpress - 覆盖 wordpress 插件的 iframe 固定大小 iz 简码