Created
April 25, 2014 02:16
-
-
Save kiinlam/11275899 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
(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