利用mask-image实现斑马线光影的流水般的运动效果:
dom部分:
<div class="mask">
<div class="light"></div>
</div>
CSS:
body {
background-color: #333;
}
.mask {
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
width: 149px;
height: 8px;
background: url(../html/image/block.png) no-repeat center center / 100% 100%;
mask-image: url(../html/image/block.png);
mask-size: 100% 100%;
}
.light {
position: absolute;
left: -100px;
top: 0;
width: 100px;
height: 8px;
background-image: linear-gradient(90deg, transparent, #FFF, transparent);
animation: move 2s linear infinite;
}
@keyframes move {
0% {
left: -100px;
}
100% {
left: 150px;
}
}
最终效果: