我正在尝试创建一个jQuery插件,here是完整的代码。问题是:我需要在插件中更改为每个容器作为个人工作吗?
;(function ( $, window, document, undefined ) {
// Create the defaults once
var pluginName = 'accordion',
defaults = {
propertyName: "value"
};
// The actual plugin constructor
function Plugin( element, options ) {
this.element = element;
this.options = $.extend( {}, defaults, options) ;
this._defaults = defaults;
this._name = pluginName;
this.init();
}
Plugin.prototype.init = function () {
activeItem = $("li").first();
$(activeItem).addClass('active');
$(".tab").click(function(){
$(activeItem).animate({width: "41px"}, 500);
$(activeItem).removeClass('active');
$(this).parent().animate({width: "640px"}, 500);
activeItem = $(this).parent();
$(activeItem).addClass('active');
});
};
$.fn[pluginName] = function ( options ) {
return this.each(function () {
if (!$.data(this, 'plugin_' + pluginName)) {
$.data(this, 'plugin_' + pluginName,
new Plugin( this, options ));
}
});
}
})( jQuery, window, document );
$(document).ready(function(){
$("#acor_1").accordion();
$("#acor_2").accordion();
});