В Javascript я хочу, чтобы мое событие onmouseout находилось в режиме сна / пауза / ожидание / (не уверен в правильной терминологии здесь) в течение трех секунд, прежде чем оно вступит в силу. Как это достигается?
спасибо
function outfunction(event) { var that = this; // to be able to use this later. window.setTimeout(function() { … /* you can use 'that' here to refer to the element event is also available in this scope */ }, 3000); }
var doSomething = function () { //Some code will here after 3 seconds of mouseout }; anElement.onmouseout = function () { setTimeout(doSomething, 3000); };
Код, приведенный выше, выполняет функцию doSomething через 3 секунды после вызова onmouseout
doSomething
onmouseout