由于我已升级到 jQuery 1.7,因此 hoverIntent 事件在 UI 选项卡上不再起作用。从 jQuery 1.7 开始,选项卡会立即切换,而不是使用 hoverIntent。
这是我用来初始化 UI 选项卡的代码:
$("#featured").tabs({event: "hoverintent"}).tabs({fx:{opacity: "toggle", duration: 250}}).tabs("rotate", 7000, true);
$("#featured").hover(
function() {
$("#featured").tabs("rotate",0,true);
},
function() {
$("#featured").tabs("rotate",7000,true);
}
);
这是我在页面中包含的 hoverIntent 事件的 js:
var cfg = ($.hoverintent = {
sensitivity: 7,
interval: 100
});
$.event.special.hoverintent = {
setup: function() {
$(this).bind("mouseover", jQuery.event.special.hoverintent.handler);
},
teardown: function() {
$(this).unbind("mouseover", jQuery.event.special.hoverintent.handler);
},
handler: function(event) {
event.type = "hoverintent";
var self = this,
args = arguments,
target = $(event.target),
cX, cY, pX, pY;
function track(event) {
cX = event.pageX;
cY = event.pageY;
};
pX = event.pageX;
pY = event.pageY;
function clear() {
target.unbind("mousemove", track).unbind("mouseout", arguments.callee);
clearTimeout(timeout);
}
function handler() {
if ( ( Math.abs(pX-cX) + Math.abs(pY-cY) ) < cfg.sensitivity ) {
clear();
jQuery.event.handle.apply(self, args);
} else {
pX = cX; pY = cY;
timeout = setTimeout(handler, cfg.interval);
}
}
var timeout = setTimeout(handler, cfg.interval);
target.mousemove(track).mouseout(clear);
return true;
}
};
这里似乎有一个修复(尽管对于 UI Accordion):https ://github.com/jquery/jquery-ui/commit/f0f54e38d8eab613d7ea25d698b81126e5263d83#diff-0
见演示:http: //jqueryui.com/demos/accordion/hoverintent.html
但是,我不确定如何让 hoverIntent 再次工作。必须对上面的代码进行哪些更改?很高兴有任何帮助!