css - 使 CSS Shimmer Effect 工作于已加载的图像
问题描述
我有以下微光效果在元素上使用时效果很好,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*/
}
}
<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" />
推荐阅读
- spring - Spring Boot 外键实体 null
- matlab - 为图像中的多个像素赋值
- javascript - 需要在操作时刷新功能
- c++ - 类成员作为 C++ 中 C 样式事件的事件处理程序
- python - 芹菜“成功”但 Redis 中没有结果
- maven - SpringCloud 功能应用程序的 Maven 包不起作用
- android - 如何在具有 <8 个 CPU 的主机上强制使用 android 模拟器中的多个内核
- php - 如何获得带有号码的第二个匹配组?
- elasticsearch - Elasticsearch 复杂聚合一个嵌套值减去第二个嵌套值并按第三个嵌套值分组
- kotlin - 如何为 Kodein Injected 实例传递参数?