jquery Plugin Development to realize the jquery accordion function

Source: Internet
Author: User
Tags jquery accordion

  needs an accordion effect, just write one. In fact, there are a number of off-the-shelf jquery accordion plugin can be used, but compared to a bit, always feel a little bulky, or write their own skeleton of the clearest, it is easier to expand the

Can be used for pictures or containers, using the same way as a regular jquery plug-in. The principle of implementation is not difficult to understand, both in code comments. Want to study can look at the following code, or sample demo.     Code as follows:;(function ($) {   /*      * simple accordion Toggle plugin based on jquery      */    $.fn.iaccordion=function (Iset) {        var self=this;         Iset=$.exten D ({Type: ' mouseover ', Select: ' img ', cur:0,initinterval:100,interval:500,easing: '},iset| | {});        //         * Type: Mouse event type, Mouseover,click,mouseleave etc          * Select: Selector to get the set of elements to be toggled          * Cur: Index of the default expansion element       &N Bsp  * initinterval: Initialization accordion effect animation interval          * Interval: Mouse event animation interval        * easing: animation effect, need jquery.easing support, parameters can refer to jquery.easing@ http://gsgd.co.uk/sandbox/jquery/easing/         */        var Item,boxw,selectw,animatew,sindex,animatel;   &NBSP     $ (self). each (function () {           //init container style         &NB Sp   $ (this). css ({' position ': ' relative ', ' overflow ': ' Hidden '});             item=$ (this)-find (Iset.select);            //initialization toggle element style             item.css ({' position ': ' ABSO lute ', ' left ': 0, ' top ': 0} ';             boxw=$ (this) outerwidth ();             selectw=item.outerwidth ();             animatew= (BOXW-SELECTW)/(Item.size ()-1);            //initialization element arrangement and for element data an index value             Item.each (funct Ion (i) {                $ (this) animate ({' Left ': animatew*i+ ' px '}, iset.initinterval,iset.easing);                 $ (this). Data (' index ', i);       &NBsp    }). On (Iset.type,function (e) {//Bind mouse event                //Get current element index value &NB Sp               sindex=$ (this). Data (' index ');                    //mouse event animation by judging the size relationship between element index value and current element index value animate the current element and animate the                     Item.each (function (n) {                        n > Sindex? animatel=selectw+animatew* (n-1): animatel=animatew*n;                         $ (this). Stop (). Animate ({' Left ': Animate l+ ' px '},iset.interval,iset.easing);                    }            }). EQ (iset.cur). Trigger (Iset.type);        });    }}) (JQuery);     How to call? 1, in the page to introduce the above plug-in code; 2, $ (selectmain). iAccOrdion ({...}); 3, related parameters and functions, please refer to the note in the plugin. Small hint, if need to define easing, need to import jquery.easing plug-in, easing parameter namely Jquery.easing method name, such as Easeoutbounce, Easeoutquint and so on.  

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.