如何获得关键帧动画?

时间:2020-05-22 08:31:56

标签: html css safari css-animations keyframe

我正在尝试制作涟漪效果的动画。它似乎可以在chrome浏览器上正常工作,但不能在safari上工作,而且我在同一页面上还有其他动画,它们在chrome和safari上都可以正常工作,但不是这个。我想知道我在做什么错。

我尝试对其进行调试,并且可以看到Safari图形选项卡中显示一条消息

“此动画没有关键帧”

我的CSS代码:

.ripple-animation {
    &::after {
        @include rings(2s, 40s);
    }
    &::before {
        @include rings(2s, 40s);
    }
}

@mixin rings($duration, $delay) {
    opacity: 0.5;
    // display: flex;
    flex-direction: row;
    justify-content: center;
    align-items: center;
    position: absolute;
    top: -8px;
    left: -10px;
    right: 0;
    bottom: 0;
    content: '';
    height: 120%;
    width: 110%;
    border: 4px solid rgba(0, 0, 0, 0.4);
    border-radius: 100%;

    -webkit-animation-name: ripple;
    -webkit-animation-duration: $duration;
    -webkit-animation-delay: $delay;
    -webkit-animation-iteration-count: infinite;
    -webkit-animation-timing-function: cubic-bezier(.65, 0, .34, 1);

    animation-name: ripple;
    animation-duration: $duration;
    animation-delay: $delay;
    animation-iteration-count: infinite;
    animation-timing-function: cubic-bezier(.65, 0, .34, 1);

}

@-webkit-keyframes ripple {
    from {
        opacity: 1;
        -webkit-transform: scale3d(0.8, 0.8, 0.5);
        transform: scale3d(0.8, 0.8, 0.5);
    }
    to {
        opacity: 0;
        -webkit-transform: scale3d(1.1, 1.1, 1);
        transform: scale3d(1.1, 1.1, 1);
    }

}

@keyframes ripple {
    from {
        opacity: 1;
        -webkit-transform: scale3d(0.8, 0.8, 0.5);
        transform: scale3d(0.8, 0.8, 0.5);
    }
    to {
        opacity: 0;
        -webkit-transform: scale3d(1.1, 1.1, 1);
        transform: scale3d(1.1, 1.1, 1);
    }
}

5 个答案:

答案 0 :(得分:2)

原因可能是您的浏览器不支持该代码中使用的某些内容。在动画和过渡中,“某物”实际上是伪元素::before::after

即使使用-webkit,也没有Safari浏览器支持此功能。 Safari iOS也是如此。


跨浏览器对::before::after的动画和过渡支持。

答案 1 :(得分:1)

你用萨斯写的东西。这不是正常的CSS语法。我刚刚将您的代码修改为CSS。这些样式已在野生动物园中应用。

如果要使用Sass,则最好使用预编译器将您的Sass代码编译为CSS。

.ripple-animation {
    background: red;
 }

.ripple-animation::after, .ripple-animation::before {
     opacity: 0.5;
     // display: flex;
     flex-direction: row;
     justify-content: center;
     align-items: center;
     position: absolute;
     top: -8px;
     left: -10px;
     right: 0;
     bottom: 0;
     content: '';
     height: 120%;
     width: 110%;
     border: 4px solid rgba(0, 0, 0, 0.4);
     border-radius: 100%;

     -webkit-animation-name: ripple;
     -webkit-animation-duration: 2s;
     -webkit-animation-delay: 1s;
     -webkit-animation-iteration-count: infinite;
     -webkit-animation-timing-function: cubic-bezier(.65, 0, .34, 1);


     animation-name: ripple;
     animation-duration: 2s;
     animation-delay: 1s;
     animation-iteration-count: infinite;
     animation-timing-function: cubic-bezier(.65, 0, .34, 1);
}







 @-webkit-keyframes ripple {
     from {
         opacity: 1;
         -webkit-transform: scale3d(0.8, 0.8, 0.5);
         transform: scale3d(0.8, 0.8, 0.5);
     }

     to {
         opacity: 0;
         -webkit-transform: scale3d(1.1, 1.1, 1);
         transform: scale3d(1.1, 1.1, 1);

     }

 }

 @keyframes ripple {
     from {
         opacity: 1;
         -webkit-transform: scale3d(0.8, 0.8, 0.5);
         transform: scale3d(0.8, 0.8, 0.5);
     }


     to {
         opacity: 0;
         -webkit-transform: scale3d(1.1, 1.1, 1);
         transform: scale3d(1.1, 1.1, 1);

     }

 }
<div class="ripple-animation"></div>

答案 2 :(得分:1)

在iOS中,这似乎与在辅助功能设置中关闭减少运动功能有关。您必须取消选中它,而且我认为如果仍然无法正常工作,则必须更改Safari的版本

答案 3 :(得分:1)

在VS Code中使用SASS编译器(由ritwickey)。它会自动生成CSS,通过添加诸如-webkit-animation-name:之类的额外CSS来使您的代码兼容,从而确保您的CSS在任何地方都是兼容的

答案 4 :(得分:1)

很遗憾,我没有Mac可以检查/调试代码,您可以尝试使用apt而不是0% - 100%吗? Safari有时会有一些奇怪的怪癖。

例如:

from - to