Задержка setTimeout и mouseenter
Код
$(document).ready(function(){ $(".annotation span").mouseenter(function() { $(this).next("em").animate({opacity: "show", top: "-70"}, "fast"); }); $(".annotation span").mouseleave(function() { $(this).next("em").animate({opacity: "hide", top: "-70"}, "fast"); }); }); Нужно, чтоб выполнялся animate только при задержке курсора на ".annotation span" от 1 секунды. На сколько я понял, следует вставить setTimeout(). Пробовал - безрезультатно. Ткните плз, носом :) То есть, чтоб при случайном наведении не выполнялся "animate". |
webinsoul,
Реакция на нааведение мыши |
рони,
спасибо за ссылку. Подставил свои значения (скорей всего накосячил): $(document).ready(function () { var timer; $(".annotation span").mouseenter(function () { timer = window.setTimeout(function () { $(this).next("em").stop(true, true).animate({opacity: "show", top: "-70"}, 100); }, 1000) }).mouseleave(function () { window.clearTimeout(timer) $(this).next("em").animate({opacity: "hide", top: "-40"}, 100); }); }); mouseleave работает, а mouseenter - нет. Подскажите где ошибка. |
$(".annotation span").mouseenter(function () { var th = $(this); timer = window.setTimeout(function () { th.next("em").stop(true, true).animate({opacity: "show", top: "-70"}, 100); }, 1000) |
webinsoul,
откуда таймеру знать что есть this? сохраните в переменной и в функции замените $(this) $(document).ready(function () { var timer; $(".annotation span").mouseenter(function () { var el = $(this); timer = window.setTimeout(function () { el.next("em").stop(true, true).animate({opacity: "show", top: "-70"}, 100); }, 1000) }).mouseleave(function () { window.clearTimeout(timer) $(this).next("em").animate({opacity: "hide", top: "-40"}, 100); }); }); |
Часовой пояс GMT +3, время: 06:15. |