инициализация скриптов: минимум действий
Element.delayedHover()
Element.Methods.delayedHover =
function(element, handler, delay) {
element = $(element);
var delayed =
handler.getDelayedHandlers(delay);
element.observe('mouseover',
delayed.handlers.over);
element.observe('mouseout',
delayed.handlers.out);
return delayed;
}
Function.getDelayedHandlers()
var over = function() {
if (timeouts.out) {
clearTimeout(timeouts.out);
timeouts.out = null;
}
timeouts.over = setTimeout(
function () { __function(true); }, overDelay)
};
var out = function() {
if (timeouts.over) {
clearTimeout(timeouts.over);
timeouts.over = null;
}
timeouts.out = setTimeout(
function () { __function(false); }, outDelay)
};
пример использования
var tooltip = $('helpTooltip');
function showTooltip (hover) {
if (hover) {
tooltip.show();
} else {
tooltip.hide();
}
}
$('helpButton').delayedHover(
showTooltip,
{over: 200, out: 100}
);