<html>
<head>
<meta http-equiv= "Content-Type"
content= "text/html; charset=utf-8" >
<title>slider幻灯片 - 纯JS简化版</title>
<style type= "text/css" >
*{margin: 0; padding: 0;}
/* slider */
#sliderbox { width: 500; height:313px;position: relative; overflow: hidden;margin: 20px;}
#slider {list-style: none; margin: 0; padding: 0;}
#slider li {float:left; margin: 0; padding: 0;}
#slidertab {position: absolute; right: 10px; bottom:10px; width: 80px; height: 20px; list-style: none;}
#slidertab li {float: left; width: 20px; height: 20px; margin: 2px; background: #eee;text-align: center; line-height: 20px;font-size: 12px;}
#slidertab li.sliderclass {background: #f00;}
</style>
<script type= "text/javascript" >
window.onload = function () {
var
sliderbox = document.getElementById( ‘sliderbox‘ );
var
slider = document.getElementById( ‘slider‘ );
var
sliderli = slider.getElementsByTagName( ‘li‘ );
var
slidertab = document.getElementById( ‘slidertab‘ );
var
slidertabli = slidertab.getElementsByTagName( ‘li‘ );
var
inow = 0;
sliderbox.onmouseover = function () {
clearInterval(timer);
}
sliderbox.onmouseout = function () {
//clearInterval(timer);
timer = setInterval(autoplay, 1000);
}
for ( var
i=0; i<slidertabli.length; i++) {
slidertabli[i].index = i;
slidertabli[i].onclick = function () {
clearInterval(timer);
for ( var
a=0; a<slidertabli.length; a++) {
slidertabli[a].className = "" ;
sliderli[a].style.display = "none" ;
}
this .className = "sliderclass" ;
sliderli[ this .index].style.display = "block" ;
inow = this .index;
}
}
function
autoplay() {
for ( var
i=0; i<sliderli.length; i++) {
sliderli[i].style.display = ‘none‘ ;
slidertabli[i].className = "" ;
}
sliderli[inow].style.display = ‘block‘ ;
slidertabli[inow].className = "sliderclass" ;
inow = inow==sliderli.length-1 ? 0 : inow+1;
}
timer = setInterval(autoplay, 1000);
}
</script>
</head>
<body>
<div id= "sliderbox" >
<ul id= "slider" >
<li><img src= "tab1.jpg"
/></li>
<li><img src= "tab2.jpg"
/></li>
<li><img src= "tab3.jpg"
/></li>
</ul>
<ul id= "slidertab" >
<li>1</li>
<li>2</li>
<li>3</li>
</ul>
</div>
</body>
</html>
|