Skip to content

Instantly share code, notes, and snippets.

@ethyde
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ethyde/135e5165a9ea24ba3398 to your computer and use it in GitHub Desktop.
Save ethyde/135e5165a9ea24ba3398 to your computer and use it in GitHub Desktop.
Simple jQuery base plugin
$(document).ready(function() {
// put all your jQuery goodness in here.
$('#sandbox').pluginName({
fontSize : '2em',
onComplete : function() {
$( this ).fadeOut( 5000 );
},
onSetup : function() {
$( this ).css( 'color', 'blue' );
}
});
});
;(function( window, document, $, undefined ) {
'use strict';
$.fn.pluginName = function( options ) {
options = $.extend( $.fn.pluginName.defaults, options );
// Plugin code
return this.each( function() {
var element = $( this );
element.animate({
marginLeft : options.fromLeft,
fontSize : options.fontSize
}, {
complete : options.onComplete // call "onComplete" animate callback
}
);
// call "onSetup" callback and apply the scope:
if ( $.isFunction( options.onSetup ) ) {
options.onSetup.call( element );
}
});
};
// Set up the default options.
$.fn.pluginName.defaults = {
fromLeft : '+=50',
fontSize : '20px',
onComplete : null,
onSetup : null
};
})( window, document, jQuery );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment