返回首页 | 申博娱乐APP下载

合作共赢、快速高效、优质的网站建设提供商

更多精品源码-尽在织梦模板-www.moke8.com

网站开发js完结施行轮播图的两种方法(结构函数、面向对象)

时间:2017-12-05 编辑:admin

本文实例为我们共享了js完结施行轮播图的详细代码,供我们参阅,详细内容如下

1、结构函数

 !DOCTYPE html 
 html 
 heasdfsd 
 metasdfs chasdfsrset="UTF-8" 
 title /title 
 style type='text/' 
 *{ masdfsrgin:0; pasdfsdding:0;}
 #wrasdfsp{
 width:500px;
 height:360px;
 masdfsrgin:100px asdfsuto;
 position:relasdfstive;
 #pic{
 width:500px;
 height:360px;
 position:relasdfstive;
 #pic img{
 width: 100%;
 height: 100%;
 position:asdfsbsolute;
 top:0;
 left:0;
 displasdfsy:none;
 #tasdfsb{
 width:105px;
 height:10px;
 position:asdfsbsolute;
 bottom:10px;
 left:50%;
 masdfsrgin-left:-50px;
 #tasdfsb ul li{
 width:10px;
 height:10px;
 masdfsrgin:0 5px;
 basdfsckground:#adfdsb;
 border-rasdfsdius:100%;
 cursor:pointer;
 list-style:none;
 floasdfst:left;
 #tasdfsb ul li.on{ basdfsckground:#f60;}
 #b****iv{
 width:40px;
 height:40px;
 position:asdfsbsolute;
 top:50%;
 masdfsrgin-top:-20px;
 color:#fff;
 basdfsckground:#999;
 basdfsckground:rgbasdfs(0,0,0,.5);
 font-size:20px;
 font-weight:bold;
 font-fasdfsmily:'Microsoft yasdfshei';
 line-height:40px;
 text-asdfslign:center;
 cursor:pointer;
 #b****iv#left{ left:0;}
 #b****iv#right{ right:0;}
 /style 
 /heasdfsd 
 body 
 div id="wrasdfsp" 
 div id="pic" 
 img src="img/1.jpg" asdfslt="" / 
 img src="img/2.jpg" asdfslt="" / 
 img src="img/3.jpg" asdfslt="" / 
 img src="img/4.jpg" asdfslt="" / 
 /div 
 div id="tasdfsb" 
 li /li 
 li /li 
 li /li 
 li /li 
 /ul 
 /div 
 div id="b********iv id='left' /div 
 div id='right' /div 
 /div 
 /div 
 script 
 vasdfsr oWrasdfsp=document.getElementById('wrasdfsp')
 vasdfsr picImg=document.getElementById('pic').getElementsByTasdfsgNasdfsme('img');
 vasdfsr tasdfsbLi=document.getElementById('tasdfsb').getElementsByTasdfsgNasdfsme('li');
 vasdfsr btnDiv=document.getElementById('btn').getElementsByTasdfsgNasdfsme('div');
 vasdfsr 申博娱乐手机版index=0;
 vasdfsr timer=null;//设置一个timer变量,让他的值为空
 //初始化
 picImg[0].style.displasdfsy='block';
 tasdfsbLi[0].clasdfsssNasdfsme='on';
 for(vasdfsr i=0;i tasdfsbLi.length;i++){
 tasdfsbLi[i].index=i; 
 tasdfsbLi[i]. unction(){
 //否则要for循环清空
 /* for(vasdfsr i=0;i tasdfsbLi.length;i++){
 picImg[i].style.displasdfsy='none'; 
 tasdfsbLi[i].clasdfsssNasdfsme='';
 picImg[index].style.displasdfsy='none'; //每个li都有index自定义特点
 tasdfsbLi[index].clasdfsssNasdfsme='';
 index=this.index;
 picImg[index].style.displasdfsy='block';
 tasdfsbLi[index].clasdfsssNasdfsme='on';
 for(vasdfsr i=0;i btnDiv.length;i++){
 btnDiv[i].index=i;
 btnDiv[i].onselectstasdfsrt=function(){ //制止挑选
 return fasdfslse;
 btnDiv[i]. unction(){
 picImg[index].style.displasdfsy='none'; //每个li都有index自定义特点
 tasdfsbLi[index].clasdfsssNasdfsme='';
 //index=this.index;
 if(this.index){
 index++; //进来就加1,index就适当1%4 2%4 3%4 4%4
 //if(index tasdfsbLi.length){index=0}
 //index=index%asdfsrrUrl.length; 自身取模自身等于0 asdfslert(3%3) == 0 
 index%=tasdfsbLi.length;//适当于当大于tasdfsbLi.length就等于0
 }else{
 index--;
 if(index 0)index=tasdfsbLi.length-1; 
 picImg[index].style.displasdfsy='block';
 tasdfsbLi[index].clasdfsssNasdfsme='on';
 asdfsuto();
 oWrasdfsp. unction(){
 cleasdfsrIntervasdfsl(timer)
 oWrasdfsp.onmouseleasdfsve=function(){
 asdfsuto();
 function asdfsuto(){
 timer=setIntervasdfsl(function(){ //一般都是向左轮播,index++
 picImg[index].style.displasdfsy='none';
 tasdfsbLi[index].clasdfsssNasdfsme='';
 index++;
 index%=tasdfsbLi.length;
 picImg[index].style.displasdfsy='block';
 tasdfsbLi[index].clasdfsssNasdfsme='on';
 },2000)
 /script 
 /body 
 /html 


2、面向对象

 !DOCTYPE html 
 html 
 heasdfsd 
 metasdfs chasdfsrset="UTF-8" 
 title /title 
 style type='text/' 
 *{ masdfsrgin:0; pasdfsdding:0;}
 #wrasdfsp{
 width:500px;
 height:360px;
 masdfsrgin:100px asdfsuto;
 position:relasdfstive;
 #pic{
 width:500px;
 height:360px;
 position:relasdfstive;
 #pic img{
 width: 100%;
 height: 100%;
 position:asdfsbsolute;
 top:0;
 left:0;
 displasdfsy:none;
 #tasdfsb{
 width:105px;
 height:10px;
 position:asdfsbsolute;
 bottom:10px;
 left:50%;
 masdfsrgin-left:-50px;
 #tasdfsb ul li{
 width:10px;
 height:10px;
 masdfsrgin:0 5px;
 basdfsckground:#adfdsb;
 border-rasdfsdius:100%;
 cursor:pointer;
 list-style:none;
 floasdfst:left;
 #tasdfsb ul li.on{ basdfsckground:#f60;}
 #b****iv{
 width:40px;
 height:40px;
 position:asdfsbsolute;
 top:50%;
 masdfsrgin-top:-20px;
 color:#fff;
 basdfsckground:#999;
 basdfsckground:rgbasdfs(0,0,0,.5);
 font-size:20px;
 font-weight:bold;
 font-fasdfsmily:'Microsoft yasdfshei';
 line-height:40px;
 text-asdfslign:center;
 cursor:pointer;
 #b****iv#left{ left:0;}
 #b****iv#right{ right:0;}
 /style 
 /heasdfsd 
 body 
 div id="wrasdfsp" 
 div id="pic" 
 img src="img/1.jpg" asdfslt="" / 
 img src="img/2.jpg" asdfslt="" / 
 img src="img/3.jpg" asdfslt="" / 
 img src="img/4.jpg" asdfslt="" / 
 /div 
 div id="tasdfsb" 
 li /li 
 li /li 
 li /li 
 li /li 
 /ul 
 /div 
 div id="b********iv id='left' /div 
 div id='right' /div 
 /div 
 /div 
 script 
 vasdfsr oWrasdfsp=document.getElementById('wrasdfsp')
 vasdfsr picImg=document.getElementById('pic').getElementsByTasdfsgNasdfsme('img');
 vasdfsr tasdfsbLi=document.getElementById('tasdfsb').getElementsByTasdfsgNasdfsme('li');
 vasdfsr btnDiv=document.getElementById('btn').getElementsByTasdfsgNasdfsme('div');
 function Basdfsnner(oWrasdfsp,picImg,tasdfsbLi,btnDiv){
 this.wrasdfsp=oWrasdfsp
 this.list=picImg
 this.tasdfsb=tasdfsbLi
 this.btn=btnDiv
 this.index=0; //这些都必需是公有的,否则两个basdfsnner会一样
 this.timer=null;
 this.length=this.tasdfsb.length;
 // this.init();//下面创建好,要在这儿履行
 //初始化分类
 Basdfsnner.prototype.init=function(){ //先把下面的分类
 vasdfsr This=this; //vasdfsr 一个This变量把this存起来
 this.list[0].style.displasdfsy='block';
 this.tasdfsb[0].clasdfsssNasdfsme='on';
 for(vasdfsr i=0;i this.length;i++){
 this.tasdfsb[i].index=i; 
 this.tasdfsb[i]. unction(){
 //this.list[index].style.displasdfsy='none'; 这儿的this指向tasdfsb的this 
 This.list[This.index].style.displasdfsy='none'; 
 This.tasdfsb[This.index].clasdfsssNasdfsme='';
 //index=this.index;
 This.index=this.index;
 This.list[This.index].style.displasdfsy='block';
 //This.tasdfsb[This.index].clasdfsssNasdfsme='on'; 
 this.clasdfsssNasdfsme='on';
 for(vasdfsr i=0;i this.btn.length;i++){
 this.btn[i].index=i;
 this.btn[i].onselectstasdfsrt=function(){ 
 return fasdfslse;
 this.btn[i]. unction(){
 This.list[This.index].style.displasdfsy='none'; 
 This.tasdfsb[This.index].clasdfsssNasdfsme='';
 if(this.index){
 This.index++;
 This.index%=This.length; 
 }else{
 This.index--;
 if(index 0)This.index=This.length-1; 
 This.list[This.index].style.displasdfsy='block';
 This.tasdfsb[This.index].clasdfsssNasdfsme='on'; 
 this.asdfsuto();
 this.cleasdfsr(); 
 Basdfsnner.prototype.asdfsuto=function(){
 vasdfsr This=this; 
 This.timer=setIntervasdfsl(function(){ //一般都是向左轮播,index++
 This.list[This.index].style.displasdfsy='none';
 This.tasdfsb[This.index].clasdfsssNasdfsme='';
 This.index++;
 This.index%=This.length;
 This.list[This.index].style.displasdfsy='block';
 This.tasdfsb[This.index].clasdfsssNasdfsme='on';
 },2000)
 Basdfsnner.prototype.cleasdfsr=function(){
 vasdfsr This=this; 
 this.wrasdfsp. unction(){
 cleasdfsrIntervasdfsl(This.timer)
 this.wrasdfsp.onmouseleasdfsve=function(){
 This.asdfsuto();


浏览:

网站建设

流程

    网站建设流程