I am loading two fixed body background-images, both set to cover. There is text extending below the page which scrolls; as well as top and bottom navigation icons. As expected, the second background covers the first and it looks like a normal, single loaded background.
In taking tips from previous questions, I have used body {}
for the first (now hidden) background-image and body:after {}
for the second (on-top, visible, and opacity adjustable) background-image.
I can use CSS body:after {opacity:.5}
(or any other value 0->1) to achieve a single desired effect with the top background-image while keeping my text and navigation icons at full opacity. I, however, CAN NOT access the opacity value to change it. Once I am able to do so with the aid of someone more knowledgeable, I should then be able to move forward to dynamically increment a swap of values from 1->.9->.8->etc.->0 to disappear the top background-image using a timer with 11 frames and an appropriate time interval.
My successful code snippets are below along with my failed Javascript attempt at accessing the opacity value.
(P.S.: using @RickardElimää excellent ultimate answer, the top background starts out transparent and thus actually ends up as a fade-in.)
body {
background-image: url('./MyPhoto-1.jpg') ;
position: static; /* to work with Edge 10 */
/* z-index: -2 ; */
background-position: center center ;
background-repeat: no-repeat ;
background-attachment: fixed ;
background-size: cover ;
}
body:after {
content: " ";
top: 0;
left: 0;
bottom: 0;
right: 0;
background-image: url('./MyPhoto-2.jpg') ;
position: fixed ;
z-index: -2 ;
background-position: center center ;
background-repeat: no-repeat ;
background-attachment: fixed ;
background-size: cover ;
/* arbitrarily set immediately below and needing to be accessed via Javascript */
opacity: .4 ;
}
<script>//PROBLEM with scripting access to above opacity value
// document.body.getElementById("triedDivAndBodyTag").style.opacity = ".8"
document.getElementByID("body:after").style.opacity="0.8";
</script>