【发布时间】:2021-01-02 22:33:02
【问题描述】:
我正在尝试为看起来像this one 的骨架添加一个微妙的闪光动画。我目前有一个看起来像这样的屏幕(参见CodePen):
我正在尝试编写一个可以像这样接受 SVG 的骨架组件:
<div class="skeleton" aria-busy="true">
<svg width="233" height="68" viewBox="0 0 233 68" xmlns="http://www.w3.org/2000/svg">
<g opacity="0.8">
<rect x="79" y="32" width="154" height="11" rx="2" fill="black" fill-opacity="0.07"/>
<rect width="179" height="20" rx="2" fill="black" fill-opacity="0.07"/>
<rect x="79" y="52" width="84" height="11" rx="2" fill="black" fill-opacity="0.07"/>
<rect y="26" width="67" height="42" rx="2" fill="black" fill-opacity="0.07"/>
</g>
</svg>
</div>
这是我用来为 SVG 上方的微光设置动画的 CSS:
.skeleton {
overflow: hidden;
position: relative;
}
.skeleton::before {
content: '';
position: absolute;
top: 0;
left: 0;
bottom: 0;
right: 0;
background: linear-gradient(to right, rgb(243, 242, 241) 0%, rgb(237, 235, 233) 50%, rgb(243, 242, 241) 100%) 0px 0px / 90% 100% no-repeat rgb(243, 242, 241);
transform: translateX(-100%);
animation-name: skeleton-animation;
animation-duration: 2s;
animation-timing-function: ease-in-out;
animation-direction: normal;
animation-iteration-count: infinite;
}
@keyframes skeleton-animation {
0% {
transform: translateX(-100%);
}
100% {
transform: translateX(100%);
}
}
我正在尝试弄清楚如何使用here 所述的某种遮罩,以便动画微光只发生在 SVG 上。
【问题讨论】:
-
这可能会有所帮助 ... svg 渐变蒙版 ... 大约在页面下方的 1/2 ... smashingmagazine.com/2015/12/animating-clipped-elements-svg
标签: html css svg css-animations