<!DOCTYPE html>
<html lang=
"en"
>
<head>
<meta charset=
"UTF-"
>
<title>最简单的轮播广告</title>
<style>
body, div, ul, li {
margin: ;
padding: ;
}
ul {
list-style-type: none;
}
body {
background: #;
text-align: center;
font: px/px Arial;
}
#box {
position: relative;
width: px;
height: px;
background: #fff;
border-radius: px;
border: px solid #fff;
margin: px auto;
}
#box .list {
position: relative;
width: px;
height: px;
overflow: hidden;
border: px solid #ccc;
}
#box .list li {
position: absolute;
top: ;
left: ;
width: px;
height: px;
opacity: ;
transition: opacity .s linear
}
#box .list li.current {
opacity: ;
}
#box .
count
{
position: absolute;
right: ;
bottom: px;
}
#box .
count
li {
color: #fff;
float: left;
width: px;
height: px;
cursor: pointer;
margin-right: px;
overflow: hidden;
background: #F;
opacity: .;
border-radius: px;
}
#box .
count
li.current {
color: #fff;
opacity: .;
font-weight: ;
background: #f
}
</style>
</head>
<body>
<div id=
"box"
>
<ul
class
=
"list"
>
<li
class
=
"current"
style=
"opacity: ;"
><img src=
"img/images/.jpg"
width=
""
height=
""
></li>
<li style=
"opacity: ;"
><img src=
"img/images/.jpg"
width=
""
height=
""
></li>
<li style=
"opacity: ;"
><img src=
"img/images/.jpg"
width=
""
height=
""
></li>
<li style=
"opacity: ;"
><img src=
"img/images/.jpg"
width=
""
height=
""
></li>
<li style=
"opacity: ;"
><img src=
"img/images/.jpg"
width=
""
height=
""
></li>
</ul>
<ul
class
=
"count"
>
<li
class
=
"current"
></li>
<li
class
=
""
></li>
<li
class
=
""
></li>
<li
class
=
""
></li>
<li
class
=
""
></li>
</ul>
</div>
<script>
var
box=document.getElementById(
'box'
);
var
uls=document.getElementsByTagName(
'ul'
);
var
imgs=uls[].getElementsByTagName(
'li'
);
var
btn=uls[].getElementsByTagName(
'li'
);
var
i=index=;
var
play=null;
console.log(box,uls,imgs,btn);
function
show(a){
for
(i=;i<btn.length;i++ ){
btn[i].className=
''
;
btn[a].className=
'current'
;
}
for
(i=;i<imgs.length;i++){
imgs[i].style.opacity=;
imgs[a].style.opacity=;
}
}
for
(i=;i<btn.length;i++){
btn[i].index=i;
btn[i].onmouseover=
function
(){
show(this.index);
clearInterval(play);
}
}
function
autoPlay(){
play=setInterval(
function
(){
index++;
index>=imgs.length&&(index=);
show(index);
},)
}
autoPlay();
box.onmouseover=
function
(){
clearInterval(play);
};
box.onmouseout=
function
(){
autoPlay();
};
</script>
</body>
</html>