当我尝试获取事件时,我得到了:
未捕获的类型错误:无法读取未定义的属性“类型”
我正在尝试options
通过Constructor Itoggle
tomouseInOut
然后options
进入Itoggle.prototype.mouseInOut
. 在我尝试将任何参数传递给 之前,代码工作正常mouseInOut
,现在我无法再获得event
了。即使我也尝试event
作为参数传递或任何参数。
错误:
未捕获的类型错误:无法读取未定义化妆-itoggle.js 的属性“类型”:18 Itoggle.mouseInOut 化妆-itoggle.js:18
b.event.special.(匿名函数).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);