【发布时间】:2022-01-12 01:25:20
【问题描述】:
我正在为图像制作发光效果。 为了使发光不止一种颜色,我实际上是在制作图像的伪元素副本,并应用了模糊和饱和度过滤器。这个伪元素是通过向图像的 div 添加一个类来创建的。
现在这一切都很好,但我想通过缓出来过渡发光效果,但是无论我将过渡属性放在哪里,我似乎都无法让它工作。
我制作了一个代码笔来说明: https://codepen.io/anon/pen/eYGJGPG
function addGlow() {
document.getElementById('example').classList.toggle('mask')
}
.img {
height: fit-content;
width: fit-content;
display: block;
/* Doesn't transition */
transition: all 0.3s ease-out;
-webkit-transition: all 0.3s ease-out;
-moz-transition: all 0.3s ease-out;
-o-transition: all 0.3s ease-out;
}
.go {
height: 400px;
width: 400px;
background: url("https://upload.wikimedia.org/wikipedia/commons/3/32/RGB_color_wheel_72.svg");
background-size: initial;
}
.mask::after {
content: "";
width: inherit;
height: inherit;
position: absolute;
background: inherit;
background-position: center center;
filter: blur(10px) saturate(3);
z-index: -1;
}
<div id="example" class="img go"></div>
<button onclick="addGlow()">Press</button>
【问题讨论】:
标签: html css css-transitions