I would like to create a one page website with layered cards. On page load the first two cards have to move downwards (animated) to show their content. When the user scrolls down, the other cards have to also move down card by card, when a card reaches a certain pixel height on screen. What is the best javascript to do this? Or is there a better way without javascript? It is not so important that the animation works with older browsers. Code and images to explain what I would like to do are also below.
Here is the code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Animation Test</title>
<style>
body {
background-color: white;
margin: 0;
padding: 0;
color: black;
text-align: center;
}
.shadow {
/* 35% black box shadow */
-webkit-box-shadow: 0px 10px 20px rgba(0, 0, 0, 0.35);
-moz-box-shadow: 0px 10px 20px rgba(0, 0, 0, 0.35);
box-shadow: 0px 10px 20px rgba(0, 0, 0, 0.35);
}
.container {
position: absolute;
margin: 0;
padding: 0;
width: 100%;
z-index: -10;
}
#card_1 {
position: relative;
padding-top: 50px;
width: 100%;
height: 300px;
background-color: red;
z-index: 0;
}
#card_2 {
position: relative;
padding-top: 50px;
width: 100%;
height: 300px;
background-color: green;
z-index: -1;
}
#card_3 {
position: relative;
width: 100%;
padding-top: 50px;
height: 300px;
background-color: blue;
z-index: -2;
}
#card_4 {
position: relative;
width: 100%;
padding-top: 50px;
height: 300px;
background-color: yellow;
z-index: -3;
}
#card_5 {
position: relative;
width: 100%;
padding-top: 50px;
height: 300px;
background-color: orange;
z-index: -4;
}
#card_6 {
position: relative;
width: 100%;
height: 300px;
background-color: white;
z-index: -5;
}
</style>
</head>
<body>
<div class="container">
<div id="card_1" class="shadow">
<h2>Card 1</h2>
</div>
<div id="card_2" class="shadow">
<h2>Card 2</h2>
</div>
<div id="card_3" class="shadow">
<h2>Card 3</h2>
</div>
<div id="card_4" class="shadow">
<h2>Card 4</h2>
</div>
<div id="card_5" class="shadow">
<h2>Card 5</h2>
</div>
<div id="card_6" class="shadow">
</div>
<!-- end .container -->
</div>
</body>
</html>