【发布时间】:2016-08-23 22:05:41
【问题描述】:
我想创建一个带有分层卡片的单页网站。 在页面加载时,前两张卡片必须向下移动(动画)以显示其内容。 当用户向下滚动时,当一张卡片在屏幕上达到某个像素高度时,其他卡片也必须逐张向下移动。执行此操作的最佳 javascript 是什么?或者有没有更好的方法没有javascript?动画与旧浏览器一起工作并不重要。解释我想做的事情的代码和图像也在下面。
代码如下:
<!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>
【问题讨论】:
-
“有人能这么好心,写下这个例子网站的代码吗?”据我所知,您只编写了 HTML 和 CSS。 StackOverflow 可以为您提供帮助,但您需要自己尝试一下,或进行一些研究。
-
谢谢,编辑了我的问题以寻求最佳方法。最好的JavaScript?最好的其他方式?
标签: javascript css animation