JS 轮播图
来源:互联网 发布:机械结构优化设计 编辑:程序博客网 时间:2024/05/29 02:50
<div id="banner"><div id="container"> <div id="list" style="left:-1380px;"> <img src="images/5.jpg" alt="5.pg"/> <img src="images/1.jpg" alt="5.pg"/> <img src="images/2.jpg" alt="5.pg"/> <img src="images/3.jpg" alt="5.pg"/> <img src="images/4.jpg" alt="5.pg"/> <img src="images/5.jpg" alt="5.pg"/> <img src="images/1.jpg" alt="5.pg"/> </div><div id="buttons"> <span index="1"class="on"> </span> <span index="2"></span> <span index="3"></span> <span index="4"></span> <span index="5"></span></div> <a href="javascript:;" class="arrow" id="prev"><</a> <a href="javascript:;" class="arrow" id="next">></a> </div></div>
JS
window.onload=function(){var container=document.getElementById('container');var list=document.getElementById('list');var buttons=document.getElementById('buttons').getElementsByTagName('span');var pre=document.getElementById('prev');var next=document.getElementById('next');var index=1;var animated=false;var timer;function showButton(){for(var i=0;i<buttons.length;i++){if(buttons[i].className=='on'){buttons[i].className='';break;} }buttons[index-1].className="on";}function animate(offset){ animated=true; var newleft=parseInt(list.style.left)+offset; var time=300;//位移总时间 var interval=10;//位移间隔时间 var speed=offset/(time/interval);//每一次的位移量 function go() { if((speed<0&&parseInt(list.style.left)>newleft)||(speed>0&&parseInt(list.style.left)<newleft)) { list.style.left=parseInt(list.style.left)+speed+'px'; setTimeout(go,interval); } else { animated=false; list.style.left=newleft+'px'; if(newleft>-1380) { list.style.left=-6900+'px'; } if(newleft<-6900) { list.style.left=-1380+'px'; } } } go();}function play(){timer=setInterval(function(){next.onclick();},5000);}function stop(){clearInterval(timer);} next.onclick=function(){if(index==5){index=1;}else{index+=1;}showButton();if(animated==false){animate(-1380);}}pre.onclick=function(){if(index==1){index=5;}else{ index-=1;}showButton();if(animated==false){ animate(1380);}} for(var i=0;i<buttons.length;i++){buttons[i].onclick=function(){if(this.className=='on'){return;}var myIndex=parseInt(this.getAttribute('index'));var offset=-1380*(myIndex-index); index=myIndex;showButton(); if(animated==false) {animate(offset); }} } container.onmouseover=stop; container.onmouseout=play; play();}//function validate_required(field,alerttxt)//{//with (field)//{//if (value==null||value=="")// {alert(alerttxt);return false}//else {return true}//}//}////function validate_form(thisform)//{//with (thisform)//{//if (validate_required(email,"Email must be filled out!")==false)// {email.focus();return false}//}//}
图片大小1380*460px
阅读全文
0 0
- js轮播图
- js轮播图
- js轮播图
- js轮播图
- js轮播图
- JS 轮播图
- JS轮播图
- JS-学习笔记:原生JS实现轮播图
- 原生JS实现轮播图
- 图片轮播图js、css
- js轮播图原理
- JS实现轮播图
- js无间隙轮播图
- JS无缝隙轮播图
- 原生JS轮播图
- js练习--轮播图
- JS实现轮播图
- 原生js轮播图
- 哈理工oj 1005 Counting Subsequences
- Caffe的深度学习训练全过程
- Java ConcurrentModificationException异常原因和解决方法
- 数据结构4-深度优先搜索和广度优先搜索
- [agc015f]Kenus the Ancient Greek
- JS 轮播图
- 支持向量机(SVM)算法
- iOS 宏定义~ 安全指针
- java 反射机制
- 我的python学习笔记、存储数据
- ssh跳板机使用体验
- swift语言特点
- 大型网站CAP理论和BASE模型
- ERROR 2003 (HY000):Can't connect to MySQL server on 'localhost' (10060)