Jquery封装幻灯片效果

前几天 在我同事博客里面看到一篇幻灯片 所以觉得用Jqeury写幻灯片也并不是很难 就是和我在博客里面的tab自动切换的原理是一模一样的 只是形式不同而已!所以今天也写了一个常见的幻灯片效果 用Jquery写的  很简单 也是用我上次tab自动切换的js  所以原理没有什么可说的 不懂的可以看看上次写的TAB自动切换代码:下面的一张截图:

网站建设哪家好,找创新互联公司!专注于网页设计、网站建设、微信开发、微信小程序开发、集团企业网站建设等服务项目。为回馈新老客户创新互联还提供了横峰免费建站欢迎大家使用!

 

Jquery封装幻灯片效果

就是类似这种幻灯片:

下面是HTML结构和CSS样式

 

  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. .Marquee{ width:490px; margin:50px auto 0; overflow:hidden;}  
  8. body,div,ul,li{ margin:0; padding:0;}  
  9. ul,li{ list-style:none;}  
  10. img{ display:block; border:none;}  
  11. .content-main{ width:490px; height:170px; overflow:hidden;}  
  12. .content{ width:490px; height:170px; overflow:hidden;}  
  13. .hide{ display:none;}  
  14. .menu{ width:490px; height:22px; overflow:hidden; background:#966;}  
  15. .menu li{ width:160px; height:22px; overflow:hidden; float:left; line-height:22px; text-align:center;}  
  16. .menu li.last-col{ width:170px; height:22px; overflow:hidden;}  
  17. .current{ background: #F00;}  
  18. .content a{ width:490px; height:170px; overflow:hidden; display:block;}  
  19. </style> 
  20. <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>   
  21. <script src="autoTab.js"></script> 
  22. </head> 
  23.  
  24. <body> 
  25.     <div id="Marquee" class="Marquee">   
  26.         <div class="content-main"> 
  27.             <div class="content"><a href="#" target="_blank"><img  src="p_w_picpaths/1.jpg"/></a></div> 
  28.             <div class="content hide"><a href="#" target="_blank"><img  src="p_w_picpaths/2.jpg"/></a></div> 
  29.             <div class="content hide"><a href="#" target="_blank"><img  src="p_w_picpaths/3.jpg"/></a></div> 
  30.         </div> 
  31.         <ul class="menu"> 
  32.             <li class="current">tab1</li> 
  33.             <li>tab2</li> 
  34.             <li class="last-col">tab3</li> 
  35.         </ul> 
  36.     </div>   
  37.     <script type="text/javascript"> 
  38.         new tabMarquee("#Marquee",3);  
  39.     </script> 
  40. </body> 
  41. </html> 

JS代码如下:

 

  1. // JavaScript Document 
  2.  
  3. function tabMarquee(obj,count){  
  4.     _this = this;  
  5.     _this.obj = obj;  
  6.     _this.count = count;  
  7.     _this.time = 3000;  //停留的时间 
  8.     _this.n = 0;  
  9.     var t;  
  10.     this.slider = function(){  
  11.         $(_this.obj + " .menu li").bind("mouseover",function(event){  
  12.             $(event.target).addClass("current").siblings().removeClass("current");  
  13.             var index = $(_this.obj + " .menu li").index(this);  
  14.             $(_this.obj + " .content-main .content").eq(index).show().siblings().hide();  
  15.             _this.n = index;      
  16.         })  
  17.     }  
  18.       
  19.     this.addHover = function(){  
  20.         $(_this.obj).hover(function(){  
  21.             clearInterval(t);     
  22.         },function(){  
  23.             t = setInterval(_this.autoPlay,_this.time);   
  24.         })    
  25.     }  
  26.     this.autoPlay = function(){  
  27.         _this.n = _this.n >=(_this.count-1) ? 0 : ++_this.n;  
  28.         $(_this.obj + " .menu li").eq(_this.n).trigger("mouseover");      
  29.     }  
  30.     this.factory = function(){  
  31.         this.slider();  
  32.         this.addHover();  
  33.         t = setInterval(this.autoPlay,_this.time);    
  34.     }  
  35.     this.factory();  

下面传个附件 看不懂可以下载下来先看看效果 然后稍微理解下 就ok了!其实说真的js重要  但是HTML结构和CSS样式同样重要 有时结构写好的话 css写好的话 js就很简单!!

附件:http://down.51cto.com/data/2359366

当前名称:Jquery封装幻灯片效果
标题来源:https://www.cdcxhl.com/article8/pdpdop.html

成都网站建设公司_创新互联,为您提供响应式网站品牌网站制作网站排名域名注册网站营销

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联

绵阳服务器托管