Sometimes we have to force repaint/reflow for the browser to render certain states. For instance:
window.onload = function () {
setTimeout(function(){
document.getElementById("gradient_text").innerHTML = "bar";
}, 500);
}
#gradient_div {
background: linear-gradient(#000000,#ffffff);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
}
<div id="gradient_div">
<p id="gradient_text" onload="update">
Foo
</p>
</div>
The "gradient_text" element, refuses to visually update its text to "bar". In some cases, it's enough to trigger a synchronous repaint like so:
...
setTimeout(function(){
var elem = document.getElementById("gradient_text");
// sync force repaint hack
elem.innerHTML="bar";
elem.style.display = 'none';
elem.style.display = 'block';
}, 500);
...
However, this does not work. Apparently, it requires an asynchronous hack:
window.onload = function () {
setTimeout(function(){
var elem = document.getElementById("gradient_text");
elem.innerHTML = "bar";
// async force repaint hack
var display = elem.style.display;
elem.style.display = 'none';
setTimeout(function(){
elem.style.display = display
}, 50);
}, 500);
}
#gradient_div {
background: linear-gradient(#000000,#ffffff);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
}
<div id="gradient_div">
<p id="gradient_text" onload="update">
Foo
</p>
</div>
What's causing the browser engine to behave this way? Mostly interested in Webkit/Blink.
From my comment, should make it easy to test from any browser :
I added some mix-blend-mode effect so Firefox should render something similar to what Chrome is suppose to here .