html部分
p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 31.0px Consolas; color: #2b7ec3 }
p.p2 { margin: 0.0px 0.0px 0.0px 0.0px; font: 31.0px Consolas; color: #d74200 }
p.p3 { margin: 0.0px 0.0px 0.0px 0.0px; font: 31.0px Consolas; color: #289c97 }
p.p4 { margin: 0.0px 0.0px 0.0px 0.0px; font: 31.0px Consolas; color: #4f5d66; min-height: 36.0px }
p.p5 { margin: 0.0px 0.0px 0.0px 0.0px; font: 31.0px Consolas; color: #4f5d66 }
span.s1 { color: #4f5d66 }
span.s2 { color: #2b7ec3 }
span.s3 { color: #48565d }
span.s4 { color: #289c97 }
span.s5 { color: #d74200 }
span.Apple-tab-span { white-space: pre }
<html>
<head>
<meta charset="UTF-8">
<title></title>
<link rel="stylesheet" type="text/css" href="css/reset.css"/>
<link rel="stylesheet" href="css/slidingdoors.css" />
</head>
<body>
<div id="container">
<img src="img/001.jpg"/>
<img src="img/002.jpg"/>
<img src="img/003.jpg"/>
<img src="img/004.jpg"/>
</div>
</body>
<script type="text/javascript" src="js/slidingdoors.js" ></script>
</html>
slidingdoors.css部分
p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 31.0px Consolas; color: #2b7ec3 }
p.p2 { margin: 0.0px 0.0px 0.0px 0.0px; font: 31.0px Consolas; color: #4a8a01 }
p.p3 { margin: 0.0px 0.0px 0.0px 0.0px; font: 31.0px Consolas; color: #a5b2b9 }
p.p4 { margin: 0.0px 0.0px 0.0px 0.0px; font: 31.0px Consolas; color: #929151 }
p.p5 { margin: 0.0px 0.0px 0.0px 0.0px; font: 31.0px Consolas; color: #d74200 }
span.s1 { color: #929151 }
span.s2 { color: #4f5d66 }
span.s3 { color: #48565d }
span.s4 { color: #ad42ef }
span.s5 { color: #698906 }
span.s6 { color: #d16400 }
span.s7 { color: #000000 }
span.Apple-tab-span { white-space: pre }
img{
height: 400px;
position: absolute;
display: block;
left: 0;
/*border-left: 2px solid gray;*/
}
#container{
height: 400px;
margin: 0 auto;
border-right: 2px solid #ccc;
border-bottom: 2px solid #ccc;
overflow: hidden;
position: relative;
}
js部分
p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 31.0px Consolas; color: #4663cc }
p.p2 { margin: 0.0px 0.0px 0.0px 0.0px; font: 31.0px Consolas; color: #a5b2b9 }
p.p3 { margin: 0.0px 0.0px 0.0px 0.0px; font: 31.0px Consolas; color: #4f5d66 }
p.p4 { margin: 0.0px 0.0px 0.0px 0.0px; font: 31.0px Consolas; color: #e48b00 }
p.p5 { margin: 0.0px 0.0px 0.0px 0.0px; font: 31.0px Consolas; min-height: 36.0px }
span.s1 { color: #4a8a01 }
span.s2 { color: #4f5d66 }
span.s3 { color: #e48b00 }
span.s4 { color: #698906 }
span.s5 { color: #000000 }
span.s6 { color: #4663cc }
span.s7 { color: #289c97 }
span.s8 { color: #ad42ef }
span.s9 { color: #b58a00 }
span.Apple-tab-span { white-space: pre }
window.onload = function() {
//获得容器对象
var box = document.getElementById("container");
//获得图片NodeList对象集合
var imgs = box.getElementsByTagName("img");
//单张图片的宽度
var imgWidth = imgs[0].offsetWidth;
//设置掩藏门体露出得宽度
var exposeWidth = 180;
//设置容器总宽度
var boxWidth = imgWidth + exposeWidth * (imgs.length - 1);
box.style.width = boxWidth + "px";
//设置每道门的初始位置
function setImgsPos() {
for(var i = 1; i < imgs.length; i++) {
imgs[i].style.left = imgWidth + exposeWidth * (i - 1) + "px";
}
}
setImgsPos();
//计算每道门打开时应移动的距离
var translate = imgWidth - exposeWidth;
//为每道门绑定事件
for(var i = 0; i < imgs.length; i++) {
//使用立即调用的函数表达式,为了获得不同的i值
(function(i) {
imgs[i].onmouseover = function() {
//设置每道门复位
setImgsPos();
//打开门
for (var j=1;j<=i;j++) {
imgs[j].style.left=parseInt(imgs[j].style.left)-translate+"px";
}
}
})(i);
}
}
reset css部分
p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 31.0px Consolas; color: #a5b2b9 }
p.p2 { margin: 0.0px 0.0px 0.0px 0.0px; font: 31.0px Consolas; min-height: 36.0px }
p.p3 { margin: 0.0px 0.0px 0.0px 0.0px; font: 31.0px Consolas; color: #2b7ec3 }
p.p4 { margin: 0.0px 0.0px 0.0px 0.0px; font: 31.0px Consolas; color: #4a8a01 }
p.p5 { margin: 0.0px 0.0px 0.0px 0.0px; font: 31.0px Consolas; color: #d16400 }
p.p6 { margin: 0.0px 0.0px 0.0px 0.0px; font: 31.0px Consolas; color: #929151 }
span.s1 { color: #48565d }
span.s2 { color: #4f5d66 }
span.s3 { color: #929151 }
span.s4 { color: #ad42ef }
span.s5 { color: #698906 }
span.s6 { color: #2b7ec3 }
span.s7 { color: #d16400 }
span.s8 { color: #289c97 }
span.Apple-tab-span { white-space: pre }
/* http://meyerweb.com/eric/tools/css/reset/
v2.0 | 20110126
License: none (public domain)
*/
html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, embed,
figure, figcaption, footer, header, hgroup,
menu, nav, output, ruby, section, summary,
time, mark, audio, video {
margin: 0;
padding: 0;
border: 0;
font-size: 100%;
font: inherit;
vertical-align: baseline;
}
/* HTML5 display-role reset for older browsers */
article, aside, details, figcaption, figure,
footer, header, hgroup, menu, nav, section {
display: block;
}
body {
line-height: 1;
}
ol, ul {
list-style: none;
}
blockquote, q {
quotes: none;
}
blockquote:before, blockquote:after,
q:before, q:after {
content: ‘‘;
content: none;
}
table {
border-collapse: collapse;
border-spacing: 0;
}