<div id="banner" class="banner">
<ul id="list-banner" class="list-banner fn-clear" style="left:-624px;">
<li><a href="#"><img src="images/banner4.jpg" width="624" height="200" alt="" title="" /></a></li>
<li><a href="#"><img src="images/banner1.jpg" width="624" height="200" alt="" title="" /></a></li>
<li><a href="#"><img src="images/banner2.jpg" width="624" height="200" alt="" title="" /></a></li>
<li><a href="#"><img src="images/banner3.jpg" width="624" height="200" alt="" title="" /></a></li>
<li><a href="#"><img src="images/banner4.jpg" width="624" height="200" alt="" title="" /></a></li>
<li><a href="#"><img src="images/banner1.jpg" width="624" height="200" alt="" title="" /></a></li>
</ul>
<div class="list-num-wp">
<div id="list-num" class="list-num fn-clear">
<a href="#" class="hover"></a>
<a href="#"></a>
<a href="#"></a>
<a href="#"></a>
</div>
</div>
<div class="left">
<a id="left" href="#"></a>
</div>
<div class="right">
<a id="right" href="#"></a>
</div>
</div>
.banner{position:relative;width:624px;height:200px;overflow:hidden;}
.banner .list-banner{position:absolute;width:5000px;}
.banner .list-banner li{float:left;width:624px;height:200px;}
.banner .list-num-wp{position:absolute;bottom:7px;width:624px;height:11px;}
.banner .list-num{width:100px;margin:0 auto;}
.banner .list-num a{display:inline;float:left;width:11px;height:11px;margin:0 7px; background:url(../images/list-num.png) no-repeat;}
.banner .list-num a:hover{background:url(../images/list-num-hover.png));}
.banner .list-num a.hover{background:url(../images/list-num-hover.png);}
.banner .left a{display:block;position:absolute;width:49px;height:49px;top:75px;left:4px;background:url(../images/arrow.gif) 0 0;filter: Alpha(opacity=50);-moz-opacity:.5;opacity:0.5;}
.banner .right a{display:block;position:absolute;width:49px;height:49px;top:75px;right:4px;background:url(../images/arrow.gif) 0 -49px;filter: Alpha(opacity=50);-moz-opacity:.5;opacity:0.5;}
window.onload=function(){
var prev=document.getElementById("left");
var next=document.getElementById("right");
var list_banner=document.getElementById("list-banner");
next.onclick=function(){
list_banner.style.left=parseInt(list_banner.style.left)-624+'px'; //注:html上的ul要加行间样式left:0;,否则这里动不起来
}
prev.onclick=function(){
list_banner.style.left=parseInt(list_banner.style.left)+624+'px';
}
}
function animate(offset){
list_banner.style.left=parseInt(list_banner.style.left)+offset+'px';
}
next.onclick=function(){
animate(-624);
}
prev.onclick=function(){
animate(624);
}
function animate(offset){
var newLeft=parseInt(list_banner.style.left)+offset;
list_banner.style.left=newLeft+'px';
if(newLeft<-2496){
list_banner.style.left=-624+"px";
}
if(newLeft>-624){
list_banner.style.left=-2496+"px";
}
}
var index=1;
function showDot(){
for(var i=0;i<list_num.length;i++){
list_num[i].className="";
}
list_num[index-1].className="hover";
}
next.onclick=function(){
animate(-624);
index++;
if(index>4){
index=1;
}
showDot();
}
prev.onclick=function(){
animate(624);
index--;
if(index<1){
index=4;
}
showDot();
}
for(var i=0;i<list_num.length;i++){
list_num[i].onclick=function(){
if(this.className=="hover"){
return;
}
var myIndex=parseInt(this.getAttribute("index"));
var offset=-624*(myIndex-index);
index=myIndex;
animate(offset);
showDot();
}
}
<div class="list-num-wp">
<div id="list-num" class="list-num fn-clear">
<a index="1" href="#" class="hover"></a>
<a index="2" href="#"></a>
<a index="3" href="#"></a>
<a index="4" href="#"></a>
</div>
</div>
function animate(offset){
animated=true;
var newLeft=parseInt(list_banner.style.left)+offset;
var time=300; //位移总时间
var interval=30; //位移间隔时间
var speed=offset/(time/interval); //每次移动距离
speed=speed>0?Math.ceil(speed):Math.floor(speed); //可能存在小数,取整
function go(){
if((speed < 0 && parseInt(list_banner.style.left)>newLeft)||(speed>0&&parseInt(list_banner.style.left)<newLeft)){ //newLeft目标值
list_banner.style.left=parseInt(list_banner.style.left)+speed+'px';
setTimeout(go,interval); //不止做一次运动(go函数),每隔30毫秒前进一下
}
else{
animated=false;
list_banner.style.left=newLeft+'px';
if(newLeft<-2496){
list_banner.style.left=-624+"px";
}
if(newLeft>-624){
list_banner.style.left=-2496+"px";
}
}
}
go();
}
next.onclick=function(){
if(!animated){
index++;
}
if(index>4){
index=1;
}
showDot();
if(!animated){
animate(-624);
}
}
prev.onclick=function(){
if(!animated){
index--;
}
if(index<1){
index=4;
}
showDot();
if(!animated){
animate(624);
}
}
for(var i=0;i<list_num.length;i++){
list_num[i].onclick=function(){
if(this.className=="hover"){
return;
}
var myIndex=parseInt(this.getAttribute("index"));
var offset=-624*(myIndex-index);
index=myIndex;
showDot();
if(!animated){
animate(offset);
}
}
}
function autoplay(){
timer=setInterval(function(){
next.onclick();
},1000)
}
function stopautoplay(){
clearInterval(timer);
}
banner.onmouseover=stopautoplay;
banner.onmouseout=autoplay;
autoplay();
var img_first=list_banner.getElementsByTagName("li")[0];
var img_last=list_banner.getElementsByTagName("li")[3];
list_banner.appendChild(img_first.cloneNode(true));
list_banner.insertBefore(img_last.cloneNode(true),list_banner.getElementsByTagName("li")[0]);
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有