Development of jquery plug-in and implementation of jquery accordion Functions

Source: Internet
Author: User
Tags jquery accordion

It can be used for images or containers. It is used in a different way than the conventional jQuery plug-in call. The implementation principle is not hard to understand, and is included in the Code comments. For more information, see the following code or sample demonstration.

Copy codeThe Code is as follows:
; (Function ($ ){
/*
* Simple accordion switching plug-in based on jQuery
*/
$. Fn. iAccordion = function (iSet ){
Var self = this;
ISet = $. extend ({Type: 'mouseover', Select: 'img ', Cur: 0, InitInterval: 100, Interval: 500, Easing: ''}, iSet | {});
/*
* Type: mouse event Type, mouseover, click, mouseleave, etc.
* Select: selector, used to obtain the set of elements to be switched
* Cur: Index of expanded elements by default
* InitInterval: Specifies the animation interval for initializing the accordion effect.
* Interval: animation Interval of mouse events
* Easing: animation effect, jQuery. easing support is required, parameters can be referred to jQuery. easing @ http://gsgd.co.uk/sandbox/jquery/easing/
*/
Var item, boxW, selectW, animateW, sIndex, animateL;
$ (Self). each (function (){
// Initialize the container Style
Watermark (this).css ({'position': 'relative ', 'overflow': 'hidd '});
Item = $ (this). find (iSet. Select );
// Initialize the switching element style
Item.css ({'position': 'absolute ', 'left': 0, 'top': 0 });
BoxW = $ (this). outerWidth ();
SelectW = item. outerWidth ();
AnimateW = (boxW-selectW)/(item. size ()-1 );
// Initialize the element arrangement and create an index value for the element data
Item. each (function (I ){
$ (This). animate ({'left': animateW * I + 'px'}, iSet. InitInterval, iSet. Easing );
$ (This). data ('index', I );
}). On (iSet. Type, function (e) {// bind a mouse event
// Obtain the index value of the current element
SIndex = $ (this). data ('index ');
// Mouse event animation. The animation displays the current element and arranges the animation by judging the relationship between the element index value and the current element index value.
Item. each (function (n ){
N> sIndex? AnimateL = selectW + animateW * (n-1): animateL = animateW * n;
$ (This). stop (). animate ({'left': animateL + 'px '}, iSet. Interval, iSet. Easing );
});
}). Eq (iSet. Cur). trigger (iSet. Type );
});
}
}) (JQuery );

How to call it?
1. Introduce the above plug-in code on the page;
2. $ (selectmain). iAccordion ({...});
3. For parameters and functions, see the description in the plug-in.
TIPS: To define Easing, You need to import the jQuery. easing plug-in. The Easing parameter is the name of jQuery. easing method, such as easeOutBounce and easeOutQuint.

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.