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