Investigating how browser's render works I've noticed that in chrome dev tools with enabled flag paint flashing triggers paint step on changing transform/opacity property.
Look at these screenshots with code:
Example 1 (transform/opacity property)
let elem = document.querySelector(".newLayer");
let count = 0;
function anim(){
elem.style.transform = `translate(${count}px,0)`;
/// interchangeable
/// elem.style.opacity = `${count/500}`;
if(count++ < 500)
requestAnimationFrame(anim);
}
anim();
.newLayer{
position:relative;
width:150px;
height:150px;
background-color: red;
}
<div class="newLayer">I am a new Layer</div>
Example 2 (transform/opacity property with will-change)
let elem = document.querySelector(".newLayer");
let count = 0;
function anim(){
elem.style.transform = `translate(${count}px,0)`;
/// interchangeable
/// elem.style.opacity = `${count/500}`;
if(count++ < 500)
requestAnimationFrame(anim);
}
anim();
.newLayer{
will-change: transform;
position:relative;
width:150px;
height:150px;
background-color: red;
}
<div class="newLayer">I am a new Layer</div>
It confuses me, because I've seen this one and this one sources, they say when you're using transform/opacity, paint stage is ommited. So what is it? Why do we see paint in the first example, and don't in second? Which one is lying?
Interesting one example with 2 paint operations:
let elem = document.querySelector(".newLayer");
let count = 0;
function anim(){
elem.style.left = `${count}px`;
if(count++ < 500)
requestAnimationFrame(anim);
}
anim();
.newLayer{
position:relative;
width:150px;
height:150px;
background-color: red;
}
<div class="newLayer">I am a new Layer</div>
Yes, there is used property of positioning, but look at the paint operations, one big stripe and one small such as in example without will-change. What does it mean (I am speaking about paint with tiny stripe length)?
Is the tiny paint block related with raster threads, what about big one?