I have next code to make a fade transition but my background image load first and without fading?
body {
opacity: 0;
transition: opacity 5s;
}
and then:
<body onload="document.body.style.opacity='1'">
And the background image loads first than rest.
I expect the background image loads with the same fading time than te rest.
2
Answers
Leave
<body>
as normal (noopacity
property is necessary). Define@keyframes
for the differentopacity
values. Add aposition: fixed
/z-index: 1
to a direct descendant element of<body>
(in the example below, it’s a<section>
). Assignanimation
property to said element.Details are commented in example