Skip to content

Instantly share code, notes, and snippets.

@calledt
Last active August 29, 2015 14:02
Show Gist options
  • Save calledt/ce1e135ad6d3d7240c3e to your computer and use it in GitHub Desktop.
Save calledt/ce1e135ad6d3d7240c3e to your computer and use it in GitHub Desktop.
/**
* jquery plugin template
* @authors Kimi (huanggengtao@gmail.com)
* @date 2014-10-15 09:54:42
* @version 0.0.1
*/
;(function($){
var Plugin = function( elem, options ) {
this.elem = elem;
this.$elem = $(elem);
return this.init(options);
};
Plugin.prototype = {
constructor: Plugin,
version: '0.0.1',
init: function( options ) {
this.options = $.extend({}, $.fn.plugin.default, options);
// 这里写业务逻辑
return this;
}
};
$.fn.plugin = function( options ) {
return this.each( function() {
!$(this).data('jqplugin') && $.data(this, 'jqplugin', new Plugin(this, options));
})
}
// 默认配置
$.fn.plugin.default = {
foo: 1,
bar: false
};
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment