我有两个解决方案:
filter:blur(0.2px) hack(don't ask me how it works)
.item img
{
transition: filter 250ms ease-in-out;
filter: blur(0.2px); /* the lowest value I could get on my machine: 0.12805650383234025436px */
image-rendering: -webkit-optimize-contrast; /* just in case quality degrades */
}
.item:hover img
{
filter: blur(2px);
}
除了笑话,这可能是由处理单元完成的浮点数优化引起的,所以通过将模糊设置为 .2px,我不是在为模糊(0px)设置动画,而是从另一个值开始,而不是像这样计算它(假设我们有线性缓动):
frame1: 0, frame2: .1, frame3: .2, frame4: .3, ...
它是这样计算的:
frame1: .2, frame2: .2666, frame3: .3332, ...
所以增量值已经改变,不再导致错误定位。当然这里没有适当的数学运算(这对于缓动特别棘手),但你明白了。
这也会通过抖动跳过第一帧。
Duplicate blurred image and toggle between them(也是最高效的方式)
<div class="item">
<img class="blurred" src="https://www.wikihow.com/images/thumb/2/25/Collect-Bodily-Fluid-Samples-from-a-Cat-Step-16.jpg/aid8673811-v4-728px-Collect-Bodily-Fluid-Samples-from-a-Cat-Step-16.jpg" alt="">
<img class="original" src="https://www.wikihow.com/images/thumb/2/25/Collect-Bodily-Fluid-Samples-from-a-Cat-Step-16.jpg/aid8673811-v4-728px-Collect-Bodily-Fluid-Samples-from-a-Cat-Step-16.jpg" alt="">
</div>
.item
{
position: relative;
}
.item img
{
max-width: 300px;
transition: opacity 250ms ease-in-out;
will-change: opacity;
}
.item .original
{
transition-delay: 0;
}
.item .blurred
{
position: absolute;
filter: blur(5px);
opacity: 0;
transition-delay: .1s;
}
.item:hover .original
{
opacity: 0;
transition-delay: .2s;
}
.item:hover .blurred
{
opacity: 1;
transition-delay: .1s;
}