jQueryプラグイン

[js]
/*
* jQueryテストプラグイン
*/
;(function($){
$.fn.myTest = function(options){
var opts = jQuery.extend({}, $.fn.myTest.defaults, options);

return this.each(function(){
$(this).css({width : opts.width,
height : opts.height,
background : opts.color});
});
};
//デフォルト値
$.fn.myTest.defaults = {
height : ‘200px’,
width : ‘300px’,
color : ‘blue’
};

})(jQuery);
[/js]

もし、引数にてパラメータを渡した場合デフォルト値が上書きされる。
[js]
$(function(){
$("#test").myTest({width : ‘400px’});
})
<div id="test"></div>
[/js]

This entry was posted in JavaScript, 技術情報. Bookmark the permalink.

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です