mix-blend-mode issues in Chrome

拥有回忆 提交于 2019-12-04 05:06:33

So, I think I figured the problem. During the animation, it seems like the body doesn't count as an element, thus making the yellow appear at 1 opacity. I tested with other blend mode and it always appears yellow. (when set to 'difference the expected result would be white instead of yellow)

So the fix? just add a div with 100% sizes and a black background! Then, the yellow has something to blend in and doesn't show up.

Here's the code that worked in your pen:

html - added the bg div:

<div class="bg"></div>
<div class="blend"></div>
<img src="http://lorempixel.com/500/500/">

it's css:

.bg{
  background: #000;
  position: absolute;
  width: 100%;
  height: 100%;
  margin: 0;
}
body {
  background: #000;
  width: 100%;
  height: 100%;
  margin: 0;
}

I also changed the body to fill the window so the margin weren't yellow too. Alternatively, the blend div could be sized in function of the body.

tagging @chrscblls since they wanted to know if you found anything.


EDIT :

For the other codepen the problem wasn't the same tho. They were trying to darken an image and a yellow rectangle onto a gray background.

If they didn't want the yellow to show on their gray background, the solution was simply to put the image inside a div and use ::after to blend in a color. Or even just make an empty div, give it the image as background and use the ::after.

this:

<div/>

with:

body {
  background: #333;
}

div{
  position:fixed;
  width: 500px;
  height: 500px;
  top:50px;
  left: 50px;
  mix-blend-mode: darken;
  background-image: url("http://lorempixel.com/500/500/");
}
div::after {
  content: "";
  height: 100%;
  width: 100%;
  background-color: yellow;
  mix-blend-mode: darken;
  position:absolute;
  opacity: 1;
  left: 0;
  top: 0;
}

or this:

<div><img src="http://lorempixel.com/500/500/"></div>

without the 'background-image' in the div css.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!