});
//Pass jQuery into the method so we can use any variable in javascript instead of "$"
Next, we add some changeable attributes to the plug-in so that users can make some changes according to their needs. At the same time, we should provide corresponding default values.
(function($){
$.fn.extend({
// Pass optional variables to the method
pluginname: function(options) {
Set default values separated by commas
var defaults = {
Color: '#ffffff'
$.extend(defaults, options); value
alert(o.padding);
3. Implement jQuery plug-in
Copy code
The code is as follows:
(function ($) {
$.fn.extend({
) //Plug-in name - paddingList
paddingList: function (options) {
var defaults = {
animatePadding: 10,
hoverColor: "Black"
var options = $.extend(defaults, options);
Function () {
var o = options;
// Payment element set to variables. Object
var items = $("li a", obj); $(this).css( "color", o.hoverColor);
; true, duration: 300 });
);
Finally, here’s how to use the plug-in:
Copy code
The code is as follows:
//Use plug-in
$(document). ready(function() {
$("#catagory").paddingList({ animatePadding: 30, hoverColor: "Red" });
});
Author: Friend Your source: jQuery Learning