在上篇轮播(方向上下轮播)后 感觉左右轮播也可以实现 稍微改造下就可以了 现在已经改造好了 ! 也可以实现:代码如下:

 

 
   
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
  2. <html xmlns="http://www.w3.org/1999/xhtml"> 
  3. <head> 
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
  5. <title>无标题文档</title> 
  6. <style> 
  7. ul,li{ list-style:none;} 
  8. .scrollImg{ width:1200px; height:300; position:absolute; top:0; left:0;} 
  9. .scrollImg a{ width:400px; height:300px; overflow:hidden; display:block; float:left;} 
  10. .scrollImg img{ border:none;} 
  11. .ScrollWrap{ width:400px; height:300px; overflow:hidden;margin:50px auto 0; position:relative;} 
  12. .lists{ height:20px; position:absolute; top:255px; right:10px; z-index:100;*top:270px;} 
  13. .lists li{ width:20px; height:20px; border:1px solid orange; background:#fff; float:left; margin-right:4px; display:inline; text-align:center; line-height:20px; color:orange; cursor:pointer; font-weight:700;} 
  14. .lists li.current{ height:24px; line-height:24px; background:orange; color:#fff; width:24px; margin-top:-2px;} 
  15. </style> 
  16. <script src="base.js" type="text/javascript"></script> 
  17. </head> 
  18.  
  19. <body> 
  20.     <div class="ScrollWrap"> 
  21.         <div class="scrollImg"> 
  22.             <a href="#"><img  src="image/01.jpg" width="400" height="300"/></a> 
  23.             <a href="#"><img  src="image/02.jpg" width="400" height="300"/></a> 
  24.             <a href="#"><img  src="image/03.jpg" width="400" height="300"/></a> 
  25.         </div> 
  26.         <ul class="lists"> 
  27.             <li>1</li> 
  28.             <li>2</li> 
  29.             <li>3</li> 
  30.         </ul> 
  31.     </div> 
  32.  <script type="text/javascript" src="object.js"></script> 
  33.  <script> 
  34.    var lists = getElementsByClassName("lists")[0].getElementsByTagName("li"), 
  35.        scrollImg = getElementsByClassName("scrollImg")[0]; 
  36.    var s = new Player(lists,scrollImg,undefined,3000,400); 
  37.    //s.Start(); 
  38.    //s.invoke(1); 
  39. </script> 
  40. </body> 
  41. </html> 

 

 
   
  1. function getElementsByClassName(className,context){ 
  2.         context = context || document; 
  3.         if(context.getElementsByClassName){ 
  4.             return context.getElementsByClassName(className);    
  5.         } 
  6.         var nodes = context.getElementsByTagName("*"),ret=[];//获取页面上的所有节点 
  7.         for(var i=0;i<nodes.length;i++){   //遍历所有的节点 
  8.             if(hasClass(nodes[i],className)) ret.push(nodes[i]); 
  9.         }    
  10.         return ret; 
  11.     } 
  12.      
  13. //检查有没有类 
  14. function hasClass(node,className){ 
  15.     var names = node.className.split(/\s+/);//正则表达式所有的类名用空格分开    
  16.     //遍历这个类名 
  17.     for(var i=0;i<names.length;i++){ 
  18.         if(names[i]==className) 
  19.             return true;     
  20.         } 
  21.         return false;    
  22.     } 
  23.          
  24. /** 
  25. 参数说明 
  26. curTime 当前时间 即动画已经进行了多长时间 开始时间为0 
  27. start : 开始值 
  28. dur : 动画持续多长时间 
  29. alter : 总的变化量 
  30. */ 
  31. function animate(o,start,alter,dur,fx){ 
  32.     var curTime=0; 
  33.     var t = setInterval(function(){ 
  34.         if(curTime>=dur) clearInterval(t); 
  35.         for(var i in start){ 
  36.             o.style[i] = fx(start[i],alter[i],curTime,dur) + "px";   
  37.         } 
  38.         curTime+=50; 
  39.     },50)    
  40.     return function(){ 
  41.         clearInterval(t);    
  42.     }; 
  43.  
  44. function Linear(start,alter,curTime,dur){ 
  45.     return start + curTime/dur * alter;  
  46.     //最简单的线性变化 即匀速运动     
  47. //加速运动 
  48. function Quad(start,alter,curTime,dur){ 
  49.     return start + Math.pow(curTime/dur,2)*alter;    

 

 
   
  1. // JavaScript Document 
  2.  
  3. /**  
  4. 面向对象封装轮播器 
  5. lists 轮播按钮 
  6. scrollImg 要轮播的内容 
  7. hoverClass  鼠标类 
  8. outTime 轮播间隔 
  9. */ 
  10.  
  11. function Player(lists,scrollImg,hoverClass,outTime,imageWidth){ 
  12.     hoverClass = hoverClass || "current"
  13.     outTime = outTime || 3000; 
  14.     this.lists = lists; 
  15.     this.scrollImg = scrollImg; 
  16.     this.hoverClass = hoverClass; 
  17.     this.outTime = outTime; 
  18.     this.imageWidth = imageWidth; 
  19.     this.curItem =lists[0];  //初始化当前帧 
  20.     //this.curItem.index = 0;  //初始化当前帧的值 
  21.     this.invoke(0); 
  22.     var _this = this
  23.     for(var i=0;i<this.lists.length;i++){ 
  24.         this.lists[i].onmouseover = function(){ 
  25.             _this.Stop(); 
  26.             _this.invoke(this.index); 
  27.         }; 
  28.         this.lists[i].onmouseout = function(){ 
  29.             _this.Start(); 
  30.         }; 
  31.         this.lists[i].index = i; 
  32.     } 
  33. /* start是开始播放函数 stop是结束函数 invoke是切换到哪里的函数 */ 
  34. Player.prototype = { 
  35.     Start : function(){ 
  36.         var _this = this
  37.         this.Stop(); 
  38.         this.interval = setInterval(function(){ 
  39.             _this.next();    
  40.         },this.outTime); 
  41.     }, 
  42.     invoke : function(n){ 
  43.         //具体显示那一帧 
  44.         this.curItem = this.lists[n]; 
  45.         //this.curItem.index = n; 
  46.         var left = parseInt(this.scrollImg.style.left) || 0; 
  47.         this.animateInterval && this.animateInterval(); 
  48.         this.animateInterval = animate(this.scrollImg,{left:left},{left:(-n*this.imageWidth)-left},500,Quad); 
  49.         //this.scrollImg.style.top = -n*300 + "px"; 
  50.         this.recovery(); 
  51.         this.curItem.className = this.hoverClass; 
  52.          
  53.     }, 
  54.     Stop : function(){ 
  55.         clearInterval(this.interval); 
  56.     }, 
  57.     next : function(){ 
  58.         //这个函数是说明是下一帧 那么我们应该求出当前针. 
  59.         var nextIndex = this.curItem.index + 1; 
  60.         if(nextIndex >= this.lists.length){ 
  61.             nextIndex = 0;   
  62.         }    
  63.         this.invoke(nextIndex); 
  64.     }, 
  65.     recovery : function(){ 
  66.         for(var i=0;i<this.lists.length;i++){ 
  67.             this.lists[i].className = "";    
  68.         }    
  69.     }    

 代码写到这里 突然感觉到 带左右箭头的控制按钮 原理应该也差不到了 到时候也搞下!