效果图
原理:
代码:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
* {
margin: 0px;
padding: 0px;
}
body {
margin: 0;
padding: 0;
-webkit-text-size-adjust: none;
color: #000;
}
img {
border: 0;
vertical-align: bottom;
}
.slider {
width: 470px;
height: 150px;
overflow: hidden;
position: relative;
}
.ctrl{
position: absolute;
z-index: 11;
bottom: 0px;
}
.ctrl li{
margin-left: 5px;
text-align: center;
list-style: none;
float: left;
width: 50px;
background-color: aquamarine;
color: #94ceff;
}
#box {
width: 470px;
height: 750px;
}
</style>
</head>
<body>
<div class="slider">
<div id="box" style="position: absolute;left: 0px;top: 0px">
<img src="images/1.jpg" alt="" >
<img src="images/2.gif" alt="" >
<img src="images/3.gif" alt="" >
<img src="images/4.gif" alt="" >
<img src="images/5.jpg" alt="" >
</div>
<div class="ctrl">
<ul>
<li onclick="select(0)" id="li_0">1</li>
<li onclick="select(1)" id="li_1">2</li>
<li onclick="select(2)" id="li_2">3</li>
<li onclick="select(3)" id="li_3">4</li>
<li onclick="select(4)" id="li_4">5</li>
</ul>
</div>
</div>
<script>
function select(i) {
var box = document.getElementById("box");
if(i==0){
box.style.top=0;
}else {
var pp = parseInt(box.style.top) || 0;
animate(box, {top: pp}, {top: (-i * 150) - pp}, 500, Quad);
}
var lias=document.getElementsByTagName("li");
for(var j=0;j<lias.length;j++){
lias[j].style.background="aquamarine";
}
document.getElementById("li_"+i).style.background="#FF0";
}
function autoslect() {
var a = 0;
setInterval(function () {
select(a);
if (a < 4) {
a++;
} else {
a = 0;
}
}, 1000);
}
window.onload = function () {
autoslect();
}
function animate(o, start, alter, dur, fx) {
var curTime = 0;
var t = setInterval(function () {
if (curTime >= dur) clearInterval(t);
for (var i in start) {
o.style[i] = fx(start[i], alter[i], curTime, dur) + "px";
}
curTime += 50;
}, 50);
}
function Quad(start, alter, curTime, dur) {
return start + Math.pow(curTime / dur, 2) * alter;
}
</script>
</body>
</html>