イベントを取得しようとすると、次のようになります。
Uncaught TypeError:未定義のプロパティ'type'を読み取ることができません
をに渡してoptions
から、にConstructor Itoggle
入れよmouseInOut
うとしoptions
ていItoggle.prototype.mouseInOut
ます。に引数を渡そうとする前にコードは正常に機能しますmouseInOut
が、もう取得できませevent
ん。私もevent
引数として、または任意の引数として渡そうとしても。
エラー:
Uncaught TypeError:未定義のmakeup-itoggle.js:18 Itoggle.mouseInOutmakeup-itoggle.js:18のプロパティ'type'を読み取れません
b.event.special。(無名関数) .handleb.event.dispatch
v.handle
;(function ($) {
"use strict";
var Itoggle = function (el, options) {
$(el).on('mouseenter mouseleave', mouseInOut(event, options);
};
Itoggle.prototype.mouseInOut = function (event, options) {
var $this = $(this)
, selector = $this.attr('data-target')
, target = $('#' + selector);
var opt = $.extend({}, $.fn.itoggle.defaults, options);
console.log(opt.titleActive); // ok
if (event.type == 'mouseover') {//here's come the error. Cannot read property 'type' of undefined
$this.addClass(opt.elementActive);
$this.find('.nav-button-title').addClass(opt.titleActive);
target.show();
}
else if (event.type == 'mouseout') {
$this.removeClass(opt.elementActive);
$this.find('.nav-button-title').removeClass(opt.titleActive);
target.hide();
target.mouseenter( function () {
$this.addClass(opt.elementActive);
$this.find('.nav-button-title').addClass(opt.titleActive);
target.show();
});
target.mouseleave( function () {
$this.removeClass(opt.elementActive);
$this.find('.nav-button-title').removeClass(opt.titleActive);
target.hide();
});
}
else { console.log('invalid event'); }
};
/* ITOGGLE PLUGIN DEFINITION
* ========================= */
$.fn.itoggle = function () {
return this.each( function () {
var $this = $(this)
, data = $this.data('itoggle')
, options = typeof option == 'object' && option;
if (!data) { $this.data('itoggle', (data = new Itoggle(this, options)));}
});
};
$.fn.itoggle.defaults = {
elementActive: 'nav-outer-button-active',
titleActive: 'nav-button-title-active'
};
$.fn.itoggle.Constructor = Itoggle;
})(window.jQuery);