如何在图像上制作 CSS 闪光效果?

olo*_*olo 8 css linear-gradients background-position css-animations

当在元素上使用时,我有以下闪光效果,效果非常好p,但它不适用于任何div元素,也不适用于img. 那么,我应该进行哪些修改才能确保闪光效果在任何元素上发挥作用。

片段如下

 .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*/
        }
    }
Run Code Online (Sandbox Code Playgroud)
<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>
Run Code Online (Sandbox Code Playgroud)

Tem*_*fif 34

使用面膜

.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}
}
Run Code Online (Sandbox Code Playgroud)
<p class="shimmer">Shimmering Text</p>
<img src="https://i.stack.imgur.com/MeQxk.png"class="shimmer" />
Run Code Online (Sandbox Code Playgroud)