var timerId;
element.onmouseover = function() {
timerId = setTimeout(function() {
alert(1);
}, 2000);
};
element.onmouseout = function() {
clearTimeout(timerId);
};
правильно так:
var timerId;
element.onmouseover = function() {
if( timerId ) return
timerId = setTimeout(function() {
alert(1);
}, 2000);
};
element.onmouseout = function() {
timerId = clearTimeout(timerId);
};
или так:
var timerId;
element.onmouseover = function() {
clearTimeout(timerId);
timerId = setTimeout(function() {
alert(1);
}, 2000);
};
element.onmouseout = function() {
clearTimeout(timerId);
};