LoginSignup
10
11

More than 5 years have passed since last update.

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

Posted at

プラグインを自作する際のテンプレート
”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)

10
11
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
11