10

如果您在mix-blend-mode属性之前使用动画效果,您将不会获得混合混合模式。

删除动画类或禁用动画后,mix-blend-mode将起作用。

问题是什么?我花了几个小时来解决这个简单的事情。请帮忙

.box {
  background-color:yellow; 
  overflow:hidden;
  border-radius:10px;
}

.box img{ mix-blend-mode:multiply}


.animate{  
  border:1px solid red;
  width:30px; height:30px;
  animation: spin 2s infinite linear;
}


@keyframes spin {
  0% {  transform: rotate(0deg); }
  100% { transform: rotate(1turn); }
}
<div class="animate">123</div>


<div class="box">
  <img src="https://placeimg.com/400/200/animals" alt=""> 
</div>

mix blend 无论如何都应该生效

4

3 回答 3

7

在过去,添加一个transform translateZ(0px) 用来解决很多问题。

至少在我的 Chrome 中,情况似乎仍然如此:

.box {
  background-color:yellow; 
  overflow:hidden;
  border-radius:10px;
  transform: translateZ(0px);  /* added */
}

.box img{ mix-blend-mode:multiply}


.animate{  
  border:1px solid red;
  width:30px; height:30px;
  animation: spin 2s infinite linear;
}


@keyframes spin {
  0% {  transform: rotate(0deg); }
  100% { transform: rotate(1turn); }
}
<div class="animate">123</div>


<div class="box">
  <img src="https://placeimg.com/400/200/animals" alt=""> 
</div>

于 2020-03-24T13:50:28.687 回答
3

添加mix-blend-mode到父元素也解决了这个问题。

.box {
  background-color:yellow; 
  overflow:hidden;
  border-radius:10px;
  mix-blend-mode:multiply;
}

.box img{ mix-blend-mode:multiply;}


.animate{  
  border:1px solid red;
  border-radius: 1rem;
  width:2rem; 
  height:2rem;
  animation: spin 2s infinite linear;
  display:flex;
  align-items: space-around;
  align-content: stretch;
  justify-content: space-around;
}


@keyframes spin {
  0% {  transform: rotate(0deg); background-color: aqua; }
  50% { background-color: yellow; }
  100% { transform: rotate(1turn); background-color: aqua; }
}
<div class="animate">•&lt;/div>


<div class="box">
  <img src="https://placeimg.com/400/200/animals" alt=""> 
</div>

于 2020-03-28T22:59:55.613 回答
0

在这个问题中,animate 的堆栈顺序在 box 和 img 之间,因为 animate 使用了关键帧。我认为 keyframe 改变了 animate 的堆栈顺序。所以,img 无法融入 box。我们可以使用z-index来更改元素的堆栈顺序。解决方案是 img 必须在框中。我们有两个选项。使用 z-index 的结果会有所不同。

第一个选项,我们可以在 animate 类中更改 animate 的堆栈顺序。`

.animate{
  position:relative;
  z-index:2;
}

` 结果 - 动画将在带有 img 的框的前面。

第二个选项,我们可以在盒子类中改变盒子的堆叠顺序。`

.box{
  position:relative;
  z-index:2;
}

` 结果 - 带有 img 的框将位于动画的前面。

.box {
  background-color:yellow; 
  overflow:hidden;
  border-radius:10px;
}

.box img{ mix-blend-mode:multiply}


.animate{  
  border:1px solid red;
  width:30px; height:30px;
  position:relative;
  z-index:2;
  animation: spin 2s infinite linear;
}


@keyframes spin {
  0% {  transform: rotate(0deg); }
  100% { transform: rotate(1turn); }
}
<div class="animate">123</div>


<div class="box">
  <img src="https://placeimg.com/400/200/animals" alt=""> 
</div>

于 2020-03-25T17:01:00.790 回答