要求是类似Wikipedia的工具提示,您:
//Helper to delay the event
$.fn.hoverDelay = function(handlerIn, handlerOut, delay) {
if(delay === undefined) delay = 400;
var timer;
this.on("hover",function(eventObject) {
clearTimeout(timer);
handlerIn.apply(this,eventObject);
}, function(eventObject) {
timer = setTimeout(handlerOut.bind(this, eventObject), delay);
});
};
//Attach to the task number 2, has an undefined event here
$("a[href]").hoverDelay(null,function(event){
//If the mouse hover NOT the tooltip, close it
if(!$(event.relatedTarget).is("#tooltip"))
$("#tooltip").hide();
},200)
但是然后出现未定义的event
错误。没有它,我将无法获得relatedTarget
。为什么会这样?