使用setTimeout延迟显示事件工具提示
var $liveTip = $('
').hide().appendTo('body');var tipTitle = '',showTip,delay = 300;
$('#mytable').bind('mouseover mouseout mousemove', function(event) {
var $link = $(event.target).closest('a');
if (!$link.length) { return; }
var link = $link[0];
if (event.type == 'mouseover') {
showTip = window.setTimeout(function() {
$link.data('tipActive', true);
tipTitle = link.title;
link.title = '';
$liveTip
.html('
' + tipTitle + '
' + link.href + '
').show()
.css({
top: event.pageY + 12,
left: event.pageX + 12
});
}, delay);
}
if (event.type == 'mouseout') {
if ($link.data('tipActive')) {
$link.removeData('tipActive');
$liveTip.hide();
link.title = tipTitle || link.title;
} else {
window.clearTimeout(showTip);
}
}
if (event.type == 'mousemove' && $link.data('tipActive')) {
$liveTip.css({
top: event.pageY + 12,
left: event.pageX + 12
});
}
});
Comments(0)