我有下面的微光效果,用在p元素上效果很好,但它對(duì)任何div和img都不起作用。那么,我應(yīng)該做什么修改來(lái)確保微光效果在任何元素上發(fā)揮作用呢?
片段如下
.shimmer {
display: inline-block;
color:grey;
background: #acacac -webkit-gradient(linear, 100% 0, 0 0, from(#acacac), color-stop(0.5, #ffffff), to(#acacac));
background-position: -50rem top; /*50px*/
background-repeat: no-repeat;
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
-webkit-animation-name: shimmer;
-webkit-animation-duration: 2.2s;
-webkit-animation-iteration-count: infinite;
-webkit-background-size: 50rem 100%; /*50px*/
font-size: 90px;
}
@-webkit-keyframes shimmer {
0% {
background-position: -50rem top; /*50px*/
}
70% {
background-position: 12.5rem top; /*200px*/
}
100% {
background-position: 12.5rem top; /*200px*/
}
}
<div>
<p class="shimmer">Shimmering Text</p>
<div>
<img src="https://i.stack.imgur.com/MeQxk.png" width=100 height=100 alt="Image Should Shimmer.Unfortunately not working "/>
</div>
</div>
使用遮罩
.shimmer {
color: grey;
display:inline-block;
-webkit-mask:linear-gradient(-60deg,#000 30%,#0005,#000 70%) right/300% 100%;
background-repeat: no-repeat;
animation: shimmer 2.5s infinite;
font-size: 50px;
max-width:200px;
}
@keyframes shimmer {
100% {-webkit-mask-position:left}
}
<p class="shimmer">Shimmering Text</p>
<img src="https://i.stack.imgur.com/MeQxk.png"class="shimmer" />