我有一个带有以下CSS的shimmer React组件
background: #ebebeb;
background-image: linear-gradient(to right, #ebebeb 0%, #c5c5c5 20%, #ebebeb 40%, #ebebeb 100%);我应用于它的动画关键帧如下:
{
0%: { background-position: -468px 0 };
100%: { background-position: 468px 0 };
}我的主页装载量很大。因此动画冻结了大约一秒钟左右。我读到动画转换是在线程外的https://www.phpied.com/css-animations-off-the-ui-thread/上完成的
有没有人能帮我用类似的离线方式来做我的闪光效果?
发布于 2019-10-14 03:18:05
按照链接中的建议使用transform。这是一个关于伪元素的想法:
.box {
background-image: linear-gradient(to right, #ebebeb calc(50% - 100px), #c5c5c5 50%, #ebebeb calc(50% + 100px));
background-size:0;
height: 200px;
position:relative;
overflow:hidden;
}
.box::before {
content:"";
position:absolute;
top:0;
right:0;
width:calc(200% + 200px);
bottom:0;
background-image:inherit;
animation:move 2s linear infinite;
}
@keyframes move{
to {
transform:translateX(calc(50% + 100px));
}
}<div class="box">
</div>
https://stackoverflow.com/questions/58366774
复制相似问题