首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >悬停状态下背景图像的转换

悬停状态下背景图像的转换
EN

Stack Overflow用户
提问于 2022-10-25 08:42:43
回答 2查看 31关注 0票数 0

当我把鼠标放在上面的时候,背景图像马上就会显示出来。我想表现出一个渐进式的妥协。我怎么才能解决这个问题?

代码语言:javascript
复制
.category__mid {
  min-height: 260px;
  width: 200px;
  border: 2px solid #000;
  background-size: cover;
  background-repeat: no-repeat;
  background-position: center;
  background-color: rgba(255, 255, 255, 1);
  background-blend-mode: lighten;
  transition: all 0.9s ease;
}

.category__mid:hover {
  background-color: rgba(255, 255, 255, 0);
  background-blend-mode: normal;
}
代码语言:javascript
复制
<div class="category__mid" style="background-image: url('https://i.postimg.cc/NG159gHv/pexels-kampus-production-8439682.jpg')">
  <h3>I want to show transition on hover. NOT when the user leaves</h3>
</div>

EN

回答 2

Stack Overflow用户

发布于 2022-10-25 08:47:24

将css更改为

代码语言:javascript
复制
.category__mid {
  min-height: 260px;
  background-size: cover;
  background-repeat: no-repeat;
  background-position: center;
  background-color: rgba(255,255,255,1);
  background-blend-mode: lighten;
}
.category__mid:hover {
  background-color: rgba(255,255,255,0);
  transition: all 0.9s ease ; 
}
票数 -1
EN

Stack Overflow用户

发布于 2022-10-25 09:01:01

将css更改为;

代码语言:javascript
复制
.category__mid {
      min-height: 260px;
      width: 200px;
      border: 2px solid #000;
      background-size: cover;
      background-repeat: no-repeat;
      background-position: center;
      background-color: rgba(255,255,255,1);
      background-blend-mode: lighten;
      transition: all 0.9s ease; 
    }
    .category__mid:hover {
      animation: fade-in 0.9s ease;
      background-color: rgba(255,255,255,0);
    }
    
  @keyframes fade-in {
    0% {
      background-blend-mode: lighten;
    }
    100% {
      background-blend-mode: normal;
    }
  }

不幸的是,您不能转换一个div的背景图像。

但你可以用动画。

票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/74191342

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档