Skip to content

Instantly share code, notes, and snippets.

@kiinlam
Created April 25, 2014 02:16
Show Gist options
  • Save kiinlam/11275899 to your computer and use it in GitHub Desktop.
Save kiinlam/11275899 to your computer and use it in GitHub Desktop.
jQuery plugin
(function($){
var methods = {
init : function( options ) {
return this.each(function(){
var $this = $(this),
data = $this.data('myPlugin');
// If the plugin hasn't been initialized yet
if ( ! data ) {
/*
Do more setup stuff here
*/
$(window).bind('resize.myPlugin', methods.method);
$(this).data('myPlugin', {
myPlugin : myPlugin
});
}
});
},
destroy : function( ) {
return this.each(function(){
var $this = $(this),
data = $this.data('myPlugin');
// Namespacing FTW
$(window).unbind('.myPlugin');
data.myPlugin.remove();
$this.removeData('myPlugin');
})
}
};
$.fn.myPluginName = function(options){
var options = $.extend({}, $.fn.myPluginName.defaults, options);
this.each(function(){
//插件的实现代码
});
};
// 暴露的默认参数
$.fn.myPluginName.defaults = {};
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment