【发布时间】:2021-05-21 17:37:40
【问题描述】:
我正在创建一个带有一堆滚动层(前景、中景、背景等)的场景,但令人讨厌的是,当动画重新启动时,我在 Safari (14.0.3) 上出现闪烁。这不会在 Chrome 或 Firefox 上发生。
我在这里创建了一个最小的可重现示例:
https://brendon.github.io/safari_flicker/index.html
代码如下:
.animation {
position: relative;
height: 395px;
background-image: linear-gradient(#1b9dd9, #00b6ed 44%, #ffe56c 75%);
}
.animation .scrollingAnimation {
position: absolute;
overflow: hidden;
height: 100%;
width: 100%;
}
.animation .scrollingAnimation:before {
content: "";
position: absolute;
height: 100%;
width: 200%;
}
.animation .foreground:before {
/* Dimensions: */
/* width: 1696px; */
/* height: 74px; */
min-width: 6784px;
background-image: url("https://brendon.github.io/safari_flicker/foreground.png");
background-position: left bottom -11px;
background-repeat: repeat-x;
background-size: auto 74px;
transform: translateX(-1696px);
animation: foreground 10s linear infinite;
}
@keyframes foreground {
0% {
transform: translateX(-1696px);
}
to {
transform: translateX(-3392px);
}
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<div class="animation">
<div class="foreground scrollingAnimation"></div>
</div>
</body>
</html>
这是该问题的视频:
https://github.com/brendon/safari_flicker/raw/main/flicker_video.mp4
我已经尝试了很多方法来解决这个问题。根据窗口宽度,它似乎有时会消失,但我正在寻找一个可靠的解决方案:D
iOS Safari 也存在此问题。
我应该提一下,我不想为 background-position 属性设置动画,因为这会导致性能问题并且不会被 GPU 加速。
【问题讨论】:
-
您需要在您的问题中添加一些有助于重现问题的代码。 stackoverflow.com/help/minimal-reproducible-example
-
我可以看到整个动画在 Microsoft edge - Android 上重新启动时闪烁!Check screenshot
-
@dalelandry,完成 :)
-
我在这里面临同样的问题。你找到解决方案了吗?
-
在此处查看我的答案:stackoverflow.com/a/67634347/129798 我无法以其他方式执行此操作,这很烦人,但 GSAP 使用起来还不错,而且更灵活。