您好,登錄后才能下訂單哦!
- <!DOCTYPE html>
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
- <title>jquery switchable圖片輪播</title>
- <link rel='stylesheet' href='css/reset.css'>
- <style type="text/css">
- .ui-switchable{
- margin:0px auto;
- width:690px;
- height:260px;
- border: 1px solid;
- overflow: hidden;
- }
- .ui-switchable ul{
- position: relative;
- width:130px;
- top:-260px;
- left:560px;
- }
- .ui-switchable ul li a{
- display: block;
- width:130px;
- height:33px;
- background:#fff;
- color:#666;
- text-align: center;
- letter-spacing: 1px;
- line-height: 33px;
- }
- .ui-switchable ul li a.cur{
- background: #AA0000;
- color:#fff;
- text-decoration: underline;
- }
- .ui-switchable-content-wrapper{
- width:560px;
- height:260px;
- position: relative;
- }
- .ui-switchable .ui-switchable-content{
- width:0px;
- height:0px;
- position: relative;
- }
- </style>
- <script type="text/javascript" src='http://code.jquery.com/jquery-latest.min.js'></script>
- <script type="text/javascript">
- (function($){
- $.fn.Switchable = function(config){
- var self,li,a,content,fn,cur,firstImg,curIndex = 0,len = 0;
- var _cfg = {effect:'fade'};
- var _config = $.extend({},_cfg,config);
- self = this;
- li = $('ul li',self);
- a = $('a',li);
- len = li.length;
- firstImg = a.eq(0);
- content = $("<div class='ui-switchable-content-wrapper'><img class='ui-switchable-content'></img></div>");
- //展示第一張圖片
- content.prependTo($(self)).find('img').attr('src',firstImg.attr('imgsrc'));
- show(curIndex);
- fn = setInterval(show,4000);
- a.bind('click',function(){
- curIndex = a.index($(this));
- show();
- });
- a.bind({
- 'mouseenter':function(){
- clearInterval(fn);
- },'mouseleave':function(){
- fn = setInterval(show,4000);
- }
- });
- function show(){
- cur = $('ul li a',self).eq(curIndex);
- var src = cur.attr('imgsrc');
- cur.addClass('cur').parent().siblings().find('a').removeClass('cur');
- content.find('img').attr('src',src).css({width:'0px',height:'0px',left:'280px',top:'130px'}).animate({width:'560px',height:'260px',left:'0px',top:'0px'},300,function(){
- });
- curIndex == len-1? curIndex=0:curIndex++;
- };
- };
- })(jQuery);
- </script>
- </head>
- <body>
- <div id='demo1' class='ui-switchable'>
- <ul>
- <li><a href='#' imgsrc='p_w_picpaths/01.JPG'>9折話費</a></li>
- <li><a href='#' imgsrc='p_w_picpaths/02.JPG'>年終風暴</a></li>
- <li><a href='#' imgsrc='p_w_picpaths/03.JPG'>item3</a></li>
- <li><a href='#' imgsrc='p_w_picpaths/04.JPG'>item4</a></li>
- <li><a href='#' imgsrc='p_w_picpaths/01.JPG'>item5</a></li>
- <li><a href='#' imgsrc='p_w_picpaths/02.JPG'>item6</a></li>
- <li><a href='#' imgsrc='p_w_picpaths/03.JPG'>item7</a></li>
- <li><a href='#' imgsrc='p_w_picpaths/04.JPG'>item8</a></li>
- </ul>
- </div>
- <script type="text/javascript">
- $(function(){
- $('#demo1').Switchable();
- });
- </script>
- </body>
- </html>
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。