Created
August 17, 2015 15:20
-
-
Save kovaldn/587b028a0517922bfcba to your computer and use it in GitHub Desktop.
jquery plugin
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// jQuery plugin | |
http://learn.jquery.com/plugins/basic-plugin-creation/ | |
(function ( $ ) { | |
var shade = "#556b2f"; | |
$.fn.greenify = function() { | |
this.css( "color", shade ); | |
return this; | |
}; | |
}( jQuery )); | |
$( "a" ).greenify().addClass( "greenified" ); | |
// ------------------------------------------------------ | |
// Если хотим сделать что-то с большим количеством элементов | |
$.fn.myNewPlugin = function() { | |
return this.each(function() { | |
// Do something to each element here. | |
}); | |
}; | |
// ------------------------------------------------------ | |
// Options | |
(function ( $ ) { | |
$.fn.greenify = function( options ) { | |
// This is the easiest way to have default options. | |
var settings = $.extend({ | |
// These are the defaults. | |
color: "#556b2f", | |
backgroundColor: "white" | |
}, options ); | |
// Greenify the collection based on the settings variable. | |
return this.css({ | |
color: settings.color, | |
backgroundColor: settings.backgroundColor | |
}); | |
}; | |
}( jQuery )); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment