温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

Jquery封装幻灯片效果

发布时间:2020-06-05 22:58:21 阅读:1422 作者:涂根华 栏目:web开发
前端开发者测试专用服务器限时活动,0元免费领,库存有限,领完即止! 点击查看>>

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

Jquery封装幻灯片效果

就是类似这种幻灯片:

下面是HTML结构和CSS样式

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>无标题文档</title> <style> .Marqueewidth:490pxmargin:50px auto 0overflow:hidden;}  body,div,ul,limargin:0padding:0;}  ul,lilist-style:none;}  imgdisplay:block; border:none;}  .content-mainwidth:490pxheight:170pxoverflow:hidden;}  .contentwidth:490pxheight:170pxoverflow:hidden;}  .hidedisplay:none;}  .menuwidth:490pxheight:22pxoverflow:hidden; background:#966;}  .menu liwidth:160pxheight:22pxoverflow:hidden; float:leftline-height:22pxtext-align:center;}  .menu li.last-colwidth:170pxheight:22pxoverflow:hidden;}  .currentbackground#F00;}  .content awidth:490pxheight:170pxoverflow:hidden; display:block;}  </style> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>   <script src="autoTab.js"></script> </head>  <body>     <div id="Marquee" class="Marquee">           <div class="content-main">             <div class="content"><a href="#" target="_blank"><img  src="p_w_picpaths/1.jpg"/></a></div>             <div class="content hide"><a href="#" target="_blank"><img  src="p_w_picpaths/2.jpg"/></a></div>             <div class="content hide"><a href="#" target="_blank"><img  src="p_w_picpaths/3.jpg"/></a></div>         </div>         <ul class="menu">             <li class="current">tab1</li>             <li>tab2</li>             <li class="last-col">tab3</li>         </ul>     </div>       <script type="text/javascript">         new tabMarquee("#Marquee",3);      </script> </body> </html> 

JS代码如下:

// JavaScript Document   function tabMarquee(obj,count){      _this = this;      _this.obj = obj;      _this.count = count;      _this.time = 3000;  //停留的时间      _this.n = 0;      var t;      this.slider = function(){          $(_this.obj + " .menu li").bind("mouseover",function(event){              $(event.target).addClass("current").siblings().removeClass("current");              var index = $(_this.obj + " .menu li").index(this);              $(_this.obj + " .content-main .content").eq(index).show().siblings().hide();              _this.n = index;              })      }            this.addHover = function(){          $(_this.obj).hover(function(){              clearInterval(t);             },function(){              t = setInterval(_this.autoPlay,_this.time);           })        }      this.autoPlay = function(){          _this.n = _this.n >=(_this.count-1) ? 0 : ++_this.n;          $(_this.obj + " .menu li").eq(_this.n).trigger("mouseover");          }      this.factory = function(){          this.slider();          this.addHover();          t = setInterval(this.autoPlay,_this.time);        }      this.factory();  } 

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

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

亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI

开发者交流群×