css - 鼠标离开目标时背景过渡闪烁

标签 css css-transitions

我正在尝试使用过渡为背景属性设置动画。

当我将鼠标悬停在目标上时,它运行顺畅,但当我离开时,它就像闪光!

进出不应该顺畅吗?

看起来这个闪烁的问题背后是混合模式,或者其他什么,所以我需要解释。

a {
    position:relative;
    display:block;
}

img {
    position:relative;
    width: 172px;
    border-radius:15px;
    float:left;
    margin-bottom:10px;
    filter:grayscale(100%);
}
    
a::after {
    position: absolute;
    left: 0;
    top: 0;
    width: 172px;
    height: 242px;
    background: #2d293e;
    content: " ";
    display: block;
    border-radius: 14px;
    mix-blend-mode: screen;
    transition: opacity 300ms ease-in-out,background 400ms ease-in-out;
}

a:hover::after {
    background:#FF0101;
    opacity:0.1;
}
<a>
    <img src="https://images.wikidi.net/crop/172x242/http://f2.fsm.wikidi.com/af/ad/yb/e0d20df22741de9c3480e691bc7a3a41efceddcd.jpg" alt=""/>
</a>

最佳答案

为鼠标移入和移出尝试不同的过渡,然后您将有更好的控制,并且可以避免闪光

a {
  position: relative;
  display: block;
}

img {
  position: relative;
  width: 172px;
  border-radius: 15px;
  float: left;
  margin-bottom: 10px;
  filter: grayscale(100%);
}

a::after {
  position: absolute;
  left: 0;
  top: 0;
  width: 172px;
  height: 242px;
  background: #2d293e;
  content: " ";
  display: block;
  border-radius: 14px;
  mix-blend-mode: screen;
  transition: opacity 400ms  ease-in, background 250ms  ease-in;
}

a:hover::after {
  background: #FF0101;
  opacity: 0.1;
  transition: opacity 250ms ease-in, background 400ms ease-in;
}
<a>
  <img src="https://images.wikidi.net/crop/172x242/http://f2.fsm.wikidi.com/af/ad/yb/e0d20df22741de9c3480e691bc7a3a41efceddcd.jpg" >
</a>

关于css - 鼠标离开目标时背景过渡闪烁,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60110717/

相关文章:

html - Wordpress 模板 CSS 问题

Css 100% 高度 : footer scrolling in to content when re-sizing page

javascript - 如何停止在移动设备上滚动完整日历?

javascript - 边框底部的 CSS 过渡延迟

html - CSS 箭头不透明度过渡

关于二进制属性(例如可见性)的 CSS 转换

javascript - 调用比例,但 SVG 元素也在翻译

javascript - 不使用 Jquery Mobile 的 Jquery Mobile 数据角色 ="content"?

:hover but happening on :active 上没有发生 CSS 转换

html - CSS - 使用关键帧动画时隐藏x轴上的滚动条