【发布时间】:2019-02-27 15:46:18
【问题描述】:
我正在尝试创建一个动画重复模式(斜条纹水平滑动),作为加载块的占位符(在本例中为li)。
如何使动画平滑/连续,从而产生图案无限滑动的错觉?
- 如何计算元素
width,使得模式是连续的? (条纹不应看起来破损/中断)。 - 如何让它看起来像它没有重新启动而是无限滑动一样循环? (100% 的帧应该毫无故障地传递到 0% 的帧)
目标是有一个可以添加到任何块中的类,并且在视觉上看起来像加载/处理。
注意:没有JS;纯 CSS。
li {
display: inline-block;
width: calc(20px * 8); /* how to calculate this, relative to the width (of the pattern or the step), to achieve pattern continuity exactly?
Of course without doing trying&error to know it should be 24.75px * 8.
*/
height: 200px;
background-color: blue;
background-image: repeating-linear-gradient(-45deg, transparent, transparent 10px, black 10px, black 20px);
animation: loading-slide 1s linear infinite;
}
@keyframes loading-slide {
from { background-position: 0% 0% }
to { background-position: 100% 0% }
}
<ul>
<li>test
<li>test
</ul>
【问题讨论】:
-
我在下面的公式中犯了一个小错误,现在它是正确的......我正在乘以 cos,它给出了正确的结果但不是正确的条纹数。视觉上两者是等价的,但划分更准确
-
我已经编辑以包含另一种方法;)可能更容易处理
-
感谢您的奉献、每日编辑和更正。这是一个很好的答案☺️
标签: css css-animations linear-gradients repeating-linear-gradient