jquery encapsulation function

Source: Internet
Author: User

1, plug-in name: JQuery. Plug-in name. js to pull to avoid conflicts with other libraries
//
2, custom plug-ins try to avoid using $ if you want to use $, you must pass jquery in,
Write in the last plus a parenthesis to write jquery; end encapsulation function is self-executing function
3, the end of the plug-in must be; End avoid having to do with previous code
4, encapsulation is divided into a global method and a local method
You can also continue to encapsulate more functions after the. Nav

Who to use when calling. Nav () on the line.

Global invocation in HTML

$ (function () {

$.nav ();

})

$.extend ({
Global encapsulation


})

Partial encapsulation calls

Local who need who calls

$.fn ({

})

(function () {

Encapsulates a global
$.extend ({

' Nav ': function () {
$ ('. Nav '). CSS ({
' ListStyle ': ' None ',
' Margin ': ' 0px ',
' padding ': ' 0px ',
' Display ': ' None '
})

You can no longer use $ (' list Li ') because you want to encapsulate internal lookups
Find () finds all child elements
$ ('. Nav '). Parent (). Hover (function () {
$ (this). Find ('. Nav '). Slidedown (1000);
},function () {
$ (this). Find ('. Nav '). Stop (). Slideup (1000);
});
}

})

}) (JQuery);

jquery encapsulation function

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.