一百:

所以我读了一堆关于CSS3动画不能在Safari上工作的不同的文章和堆栈溢出,等等.我try 了几个这样的例子,比如添加前缀-Webkit-使关键帧从0%到100%,甚至Transform:Translate3d(0,0,0)来触发硬件加速.我甚至try 过按某人的建议添加延迟,但不在当前的JSFidel中.到目前为止,一切都没有奏效,但我肯定这是我遗漏的一件小事.

Question

CSS动画不是我的强项,但为什么我的圈子会跳到关键帧的末尾,而不是在我的iPhone Safari/WKWebView上以无限的动画显示横扫条的效果?它可以在我的装有Chrome/Edge的Windows设备上使用.

Code

// CSS
@-webkit-keyframes ios-sweep-test {
0% {
    cx: 5;
}

100% {
    cx: 100%;
}
}

@keyframes sweep {
from {
    cx: 5;
}

to {
    cx: 100%;
}
}

circle {
animation-duration: 3s;
animation-timing-function: ease-in-out;
animation-name: sweep;
animation-iteration-count: infinite;
animation-direction: alternate;
transform:translate3d(0, 0, 0)

-webkit-animation-duration: 3s;
-webkit-animation-timing-function: ease-in-out;
-webkit-animation-name: ios-sweep-test;
-webkit-animation-iteration-count: infinite;
-webkit-animation-direction: alternate;
-webkit-transform: translate3d(0, 0, 0);
}

// HTML
<svg width="100%" height="20px">
                    <g transform="translate(0,10)">
                        <rect width="100%" height="2" y="-1" x="0" stroke="green" />
                        <circle r="4" cx="5" stroke="rgb(0, 0, 0)" fill="rgb(255, 255, 255)" />
                    </g>
                </svg>

JSFiddle

https://jsfiddle.net/2btz19qL/2/

Image

enter image description here

推荐答案

为了在我的示例中为Safari浏览器和移动设备正确过渡扫掠动画,我能够执行以下操作.

  1. 我删除了所有的-webkit前缀,它们是不需要的
  2. 我删除了转换:Translate3d(0,0,0).可能不需要这样做,但确定不需要这样做.
  3. The winning item, in the keyframes change both cx: values to percentages.

https://jsfiddle.net/1hys3rqb/

@keyframes sweep {
from {
    cx: 0%;
}

to {
    cx: 100%;
}
}

circle {
animation-duration: 3s;
animation-timing-function: ease-in-out;
animation-name: sweep;
animation-iteration-count: infinite;
animation-direction: alternate;
}

Css相关问答推荐

如何在移动屏幕尺寸上包装元素?

如何在CSS中实现边框的局部透明?

在css网格中用一个锚标签(顶部/底部边距)包装图像?

如何防止css边框缩小div?

如何在 CSS 中使 Flex 容器内的网格响应,而不 destruct 外部 Flex 容器的布局?

为什么align-content:start应用于单行项目?

如何在不使用 sx props 的情况下从 Select 样式中定位 mui paper 组件?

如何在Safari中隐藏CSS的offset-path属性?CSS支持规则不按预期工作

动态覆盖 Vuetify 类

使用 place-content: center 的全宽 CSS 网格项目

在 CSS 中,如何用破折号填充段落中每一行的空白区域?

Material UI Modal 因背景而变暗

CSS网格使sibling 项目拉伸

Ant Design:将位置子菜单移动到屏幕顶部

使用 CSS 无限期地闪烁两个不同持续时间的文本

圆形加载动画

CSS如何使元素淡入然后淡出?

在 CSS 中表示 100% 的 1/3 的最佳方式是什么?

CSS 外边框

你如何在 SASS 中定义属性 Select 器?