내 플러그인에서 다른 함수에 이벤트를 통과해야 Constructor Itoggle
에서 mouseInOut
까지이며 Itoggle.prototype.mouseInOut
안에 options
이 표시됩니다. 코드는 어떤 인수를 mouseInOut
에 전달하려고 시도하기 전에 정상적으로 작동하지만 이제는 event
을 더 이상 얻을 수 없습니다. 심지어 인수로 event
을 전달하려고해도 인수 나 인수가 사용됩니다.나는 몇 가지 문제는 내가 이벤트를 얻을 때, 내가 가진
오류 :
Uncaught TypeError: Cannot read property 'type' of undefined
makeup-itoggle.js:18Itoggle.mouseInOut
makeup-itoggle.js:18
b.event.special.(anonymous function).handle
b.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);
실제 사건 처리기에'event'를 전달해야합니다 ... – elclanrs
@elclanrs 나는 이것도 될 수 있다고 생각했지만, 이렇게하면 같은 오류가 발생합니다. – cSv