I am looking to create a background that covers the entire viewport, similar to the example shown here: https://css-tricks.com/perfect-full-page-background-image/
Additionally, I want to have 5 images stacked on top of each other (essentially 5 layers of the same original graphic) that all respond and resize at the same rate. This will allow me to implement a parallax effect on each layer, so that when the mouse moves, each layer moves at a slightly different rate.
I am struggling with figuring out how to load these images. Should I load them in the HTML body or in the CSS? And how do I ensure that they are layered on top of each other (I have tried using z-index without success).
Currently, I am attempting to load each image as a background, but this approach is not working. I am in need of a different solution.
html,
body {
height: 100%;
margin: 0;
padding: 0;
}
div.home5 {
height: 100%;
margin: 0;
padding: 0;
background: url('https://www.w3schools.com/howto/img_avatar.png') no-repeat center center fixed;
background-size: cover;
background-repeat: no-repeat;
z-index: -5;
}
div.home4 {
z-index: -4;
height: 100%;
margin: 0;
padding: 0;
background: url('https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSNSvAuOC-j9NLym8Duah8cGaA_6vhov8KGH8E29j2HeHszAO1k') no-repeat center center fixed;
background-size: cover;
background-repeat: no-repeat;
}
div.home3 {
height: 100%;
margin: 0;
padding: 0;
background: url('https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRqCM25IBWmfkxQ3Kg_q8_SxQlBIckh-alD0sf2GDwgjN0XUm9u') no-repeat center center fixed;
background-size: cover;
background-repeat: no-repeat;
z-index: -3;
}
div.home2 {
height: 100%;
margin: 0;
padding: 0;
background: url('https://www.soccercric.com/uploads/news/images/1309164275952e2e897191.png') no-repeat center center fixed;
background-size: cover;
background-repeat: no-repeat;
z-index: -2;
}
div.home1 {
height: 100%;
margin: 0;
padding: 0;
background: url('http://www.gclogistics.ca/wp-content/uploads/2015/02/stefan-1-270x270.png') no-repeat center center fixed;
background-size: cover;
background-repeat: no-repeat;
z-index: -1;
}
<!-- 'Pages' -->
<div id="page1">
</div>
<div class="home5">
</div>
<div class="home4">
</div>
<div class="home3">
</div>
<div class="home2">
</div>
<div class="home1">
</div>