jquery plugin notation

Source: Internet
Author: User

There are two methods of jquery core:

1, $.extend (object) can be understood to add a static method for jquery.
2. $.fn.extend (object) can be understood to add a method to a jquery instance.

Basic use

$.extend ({        function() {            alert (one);        }    })    $.fun1 ();    $.fn.extend ({        function() {            alert ();        }    })    $ (this). fun2 ();     // equivalent to    function () {        alert;    }    $ (this). FUN3 ();

The difference between jquery (function () {}) and (function ($) {}) (jquery)

1. JQuery (function () {}) is equivalent to $ (document). Ready (function () {}) when the DOM element is loaded to complete the execution of the method

2, (function ($) {}) (JQuery) is equivalent to

var fun = function ($) {};
Fun (jQuery);

An anonymous function is defined, where jquery represents the function argument. Usually used in jquery plug-in development, the role of defining the private domain plug-in.

<div id= "link" ><a href= "#" >jQuery</a></div>

<script src= "Http://libs.baidu.com/jquery/1.9.1/jquery.min.js" ></script>
<script>
//Step01 Defining the scope of jquery(function($) { varDefaults = {//Step01 Defining the scope of jqueryAnimatepadding:20, Hovercolor:"#f90" };//defining methods in plugins varShowLink =function(obj) {$ (obj). Append ("2222"); } //extension method name for STEP02 plug-in$.fn.paddingslide =function(options) {varoptions = $.extend (defaults, options);//step03-b Merge User custom properties, default properties //STEP4 support jquery selector $ (this) this //STEP5 supports link invocation by supporting the definition of a link call return. Such calls are supported: $ ("#fixed-floor"). Paddingslide (). CSS (', '); return This. each (function() {//the This-->jquery object, $ (this), is used for DOM objects, varobj = $ ( This); varItem = $ ("a", obj); Item.hover (function() { $( This). CSS ("Color", Options.hovercolor); $( This). Stop (). Animate ({paddingLeft:options.animatePadding}, 500); ShowLink ( This); },function() { $( This). CSS ("Color", "" "); $( This). Stop (). Animate ({paddingleft:0}, 500); }); }) };}) (JQuery);

$ (function () {
$ ("#link"). Paddingslide ();
})
</script>

jquery plugin notation

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.