I have an element which I call back
covered by another element which I call front
.
Back
is set in CSS to change color on hover. Front
is set, when hovered, to disappear after a 1s
delay and the mouse pointer which was on Front
element now is on back element.
Front
disappears by setting height: 0
in JavaScript. After Front
disappears and the mouse ointer is hovering on Back
the browser doesn't rerender the hover effect on Back
which results in its color not being changed as it should.
When I try the same example by naturally removing Front
from the DOM it works fine. My app, though, requires I do this by setting height: 0
.
You can try it for yourselves in the following examples. You will see a red box and a blue box. Red is Front
and blue is Back
. When you move the mouse pointer to the red box, the red box's color changes to green
. When you move your mouse onto the blue box, after one second, it will disappear.
The point of the example is to show that after the blue box disappears, the mouse pointer now hovers on the red box and it should therefore become green
.
In this example, the blue box is removed from the DOM completely and it works as well as expected.
In this example, though, the blue box is to be removed by setting height: 0
. After disappearing, the red element won't become green
until after I move the mouse.
Is there any way to force browser to rerender?
The problem persists in Google Chrome and Microsoft Edge. Firefox works good.