<style>
* {
margin: 0;
padding: 0;
}
img {
vertical-align: top;
}
.box {
width: 730px;
height: 454px;
margin: 100px auto;
padding: 5px;
border: 1px solid #ccc;
background-color: #cccccc;
}
.inner {
width: 730px;
height: 454px;
background-color: aliceblue;
overflow: hidden;
position: relative;
}
.inner ul {
width: 1000%;
position: absolute;
top: 0;
left: 0;
z-index: 1;
}
.inner li {
float: left;
list-style: none;
}
.focused {
position: relative;
width: 100%;
height: 100%;
}
#left,
#right {
z-index: 1;
position: absolute;
width: 35px;
height: 60px;
background-color: red;
top: 50%;
margin-top: -30px;
background: rgba(0, 0, 0, .3);
color: #fff;
line-height: 60px;
text-align: center;
font-size: 25px;
cursor: pointer;
}
#right {
right: 0;
}
</style>
<div class="box" id="box">
<div class="inner">
<ul>
<li><a href="#"><img src="img/1.jpg" alt=""></a></li>
<li><a href="#"><img src="img/2.jpg" alt=""></a></li>
<li><a href="#"><img src="img/3.jpg" alt=""></a></li>
<li><a href="#"><img src="img/4.jpg" alt=""></a></li>
<li><a href="#"><img src="img/5.jpg" alt=""></a></li>
<li><a href="#"><img src="img/6.jpg" alt=""></a></li>
</ul>
<div class="focused">
<span id="left"><</span>
<span id="right">></span>
</div>
</div>
</div>
<script>
var box = my$("box");
var inner = box.children[0];
var imgWidth = inner.offsetWidth;
var ulObj = inner.children[0];
var spanObjs = inner.children[1].children;
var focused = inner.children[2];
box.onmouseover = function () {
focused.style.display = "block";
};
box.onmouseout = function () {
focused.style.display = "none";
};
var index = 0;
my$("right").onclick = function () {
if (index < ulObj.children.length - 1) {
index++;
animate(ulObj, -index * imgWidth);
}
};
my$("left").onclick = function () {
if (index > 0) {
index--;
animate(ulObj, -index * imgWidth);
}
};
</script>