css - CSS 动画在 Safari / 所有 iPhone 浏览器上表现不同
问题描述
我已经被这个问题困扰了 3 天,并且已经在 Internet 上搜索了一个解决方案,但还没有找到一个可行的解决方案。
我有一个卡通火箭飞过屏幕的动画。火箭应用了 4 个链式关键帧动画:
1.)“发射”将火箭从屏幕左侧移到右侧
2.)“rightself”旋转火箭,使其指向上方
3.)“下降”将火箭向下移动到行星
4。 )“缩小”使火箭在接近行星表面时变小
我无法在此处添加视频,但以下是视频应该和不应该如何显示的链接:
它应该是什么样子:
https ://twitter.com/planet_katie/status/1415739110505996291
它是如何在所有 iOS 浏览器和桌面 Safari 上出现故障的:
https ://twitter.com/planet_katie/status/1418312787906998275
游戏链接,如果你想自己试试:http:
//www.codeeverydamnday.com/projects/rocketblaster/index.html
火箭动画在桌面 Chrome 和 Firefox 上运行流畅,但在 Safari 中出现故障。它也可以在 Android 手机上流畅运行,但在我在 iPhone 上尝试过的每个浏览器上都会出现故障。Chrome 开发工具中的 iPhone 模拟器也显示它运行顺畅,所以我不确定为什么它不能转换为 iPhone 本身。
我尝试过的事情:
- 将我的 svg 图像更改为 png,因为我读到有时 svg 的行为会出乎意料
- 添加了所有正确的 -webkit- 前缀
- 将4个动画压缩成1个
- 在我的元素(动画名称、动画持续时间、动画迭代计数等)上添加我的 CSS 动画时使用速记格式而不是速记格式
- 包括每个动画的 0% 和 100% 关键帧
- 为第一个动画添加 0.01 秒的延迟(在某处读到这对其他人有帮助)
到目前为止,没有运气。任何人都可以查看我的代码,看看我是否遗漏了什么?注意:为简洁起见,我删除了 -moz-、-ms- 和 -o- 前缀,但它们也在我的代码中。
#rocketfire {
background-color: red;
position: absolute;
top: 100px;
left: -320px;
height: 200px;
-webkit-animation: launch 4s ease-in-out 0.01s 1 forwards,
rightself 2s ease-in-out 3.5s 1 forwards,
shrink 3.5s ease-in-out 4s 1 forwards, descend 4s ease-in-out 5s 1 forwards;
animation: launch 4s ease-in-out 1 forwards,
rightself 2s ease-in-out 3.5s 1 forwards,
shrink 3.5s ease-in-out 4s 1 forwards, descend 4s ease-in-out 5s 1 forwards;
}
@-webkit-keyframes launch {
0% {
-webkit-transform: translateX(-0px);
}
100% {
-webkit-transform: translateX(1050px);
}
}
@keyframes launch {
0% {
transform: translateX(-320px);
}
100% {
transform: translateX(1050px);
}
}
@-webkit-keyframes rightself {
0% {
-webkit-transform: translateX(1050px) rotate(0deg);
}
100% {
-webkit-transform: translateX(1050px) rotate(-82deg);
}
}
@keyframes rightself {
100% {
transform: translateX(1050px) rotate(-82deg);
}
}
@-webkit-keyframes descend {
0% {
-webkit-top: 0px;
}
100% {
-webkit-top: 270px;
}
}
@keyframes descend {
100% {
top: 270px;
}
}
@-webkit-keyframes shrink {
0% {
-webkit-transform: translateX(1050px) rotate(-82deg) scale(1);
}
100% {
-webkit-transform: translateX(1050px) rotate(-82deg) scale(0.5);
}
}
@keyframes shrink {
100% {
transform: translateX(1050px) rotate(-82deg) scale(0.5);
}
}
<img id="rocketfire" src="images/rocketfireright.png" />
解决方案
我认为您不需要-webkit
动画的版本,因此删除这些将使 CSS 更易于调试。我发现了一些不一致和缺失值。清理后,CSS 如下所示:
#rocketfire {
background-color: red;
position: absolute;
top: 100px;
left: -320px;
height: 200px;
animation: launch 4s ease-in-out 1 forwards,
rightself 2s ease-in-out 3.5s 1 forwards,
shrink 3.5s ease-in-out 4s 1 forwards,
descend 4s ease-in-out 5s 1 forwards;
}
@keyframes launch {
0% {
transform: translateX(-320px);
}
100% {
transform: translateX(1050px);
}
}
@keyframes rightself {
0% {
transform: translateX(1050px) rotate(0deg);
}
100% {
transform: translateX(1050px) rotate(-82deg);
}
}
@keyframes descend {
0% {
top: 0px;
}
100% {
top: 270px;
}
}
@keyframes shrink {
0% {
transform: translateX(1050px) rotate(-82deg) scale(1);
}
100% {
transform: translateX(1050px) rotate(-82deg) scale(0.5);
}
}
试试看它是否能解决它!
推荐阅读
- javascript - 关闭应用程序时如何根据推送通知更新 UI(React Native)
- traffic - 如何从 mininet 中的跟踪文件生成流量?
- cordova - 离子项目中的cordova-plugin-file-downloader插件如何?
- python - word2Vec 和缩写
- azure-logic-apps - 如何从 Azure Functions 在 Azure Logic App Workflow 中动态添加 SFTP 文件路径
- angular - 如何在不使用 ngbTooltip 的情况下在 Angular 4 应用程序中实现 bootstrap 4 工具提示?
- php - PHP curl:在保存到文件之前检查错误响应
- php - 使用开始时间和结束时间制定给定分钟的时间表
- python - 用于关闭 impala 查询的 Python 脚本。我正在使用 urllib 和 json 库
- css - 我可以在另一个 id 中调用 CSS id 吗?