Jquery學習外掛程式之手風琴

來源:互聯網
上載者:User

標籤:style   blog   http   color   os   io   ar   art   div   

<!DOCTYPE html><html><head>    <meta charset="utf-8">    <title>手風琴</title>    <link href="css/accordion.css" rel="stylesheet">    <script src="js/jquery-1.11.1.min.js"></script>    <script src="js/accordion.js"></script>    <script>        $(function(){            //外掛程式的應用            $("#ul1").accordion();        });    </script></head><body><ul id="ul1">    <li>111111111<span>第一塊</span></li>    <li>22222222222<span>第二塊</span></li>    <li>33333333333<span>第三塊</span></li>    <li>444444444<span>第四塊</span></li>    <li>555555555<span>第五塊</span></li></ul></body></html>
View Code

js部分

/** * Created by Iecy on 14-9-5. * 手風琴外掛程式 */;(function($){    $.fn.extend({        accordion:function(options){            var defaults = {                width:"800px",                spanWidth:20,                hideWidth:700            };            var options = $.extend(defaults,options);            var obj = $(this); //當前對象            var obj_children = obj.children();//當前對象下的子級(第一級)            var obj_childern_len = obj_children.length;//子級的個數            var aLeft = [];            obj_children.each(function(){                var index = $(this).index();                $(this).css({zIndex:obj_childern_len-index,left:options.spanWidth*index+"px"});//初始化各個li層級和位置                aLeft[index] = $(this).position().left;//儲存下各個手風琴鍵的位置            });            obj_children.mouseover(function(){                var index = $(this).index();                obj_children.each(function(){                    if($(this).index()<index){                        obj_children.eq($(this).index()).stop().animate({left:aLeft[$(this).index()]-options.hideWidth+"px"});                    }else{                        obj_children.eq($(this).index()).stop().animate({left:aLeft[$(this).index()]+‘px‘});                    }                });            });        }    });})(jQuery);
View Code

css部分

 * {margin:0; padding:0; list-style:none;}        /*展開:720px        收合:20px*/        #ul1 {width:800px; height:400px; border:1px solid red; margin:10px auto; position:relative; overflow:hidden;}        #ul1 li {width:720px; height:400px; background:#CCC; position:absolute;}        #ul1 li span {position:absolute; top:0; right:0; background:#C66; width:18px; height:398px; border:1px solid black; color:white; text-align:center;}
View Code

個人練習,路過下就可以了。

Jquery學習外掛程式之手風琴

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.