11
Help us understand the problem. What are the problem?

More than 5 years have passed since last update.

posted at

jQueryプラグイン テンプレート

プラグインを自作する際のテンプレート
”test”(仮称)を任意の名前に変換して使う

(function($){

  var methods = {
    init : function( options ) {
      var elements = this
      var settings = $.extend(true, $.fn.test.defaults, options);
      console.log(settings)
      elements.each(function() {
         // 処理をここに記述する
      });
      return this;
    }
  };

  $.fn.test = function( method ) {
    if ( methods[method] ) {
      return methods[method].apply( this, Array.prototype.slice.call( arguments, 1 ));
    } else if ( typeof method === 'object' || ! method ) {
      return methods.init.apply( this, arguments );
    } else {
      $.error( 'Method ' +  method + ' does not exist on jQuery.test' );
    }
  };
  $.fn.test.defaults = {
    default: true,
  };
})(jQuery)

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Sign upLogin
11
Help us understand the problem. What are the problem?