У меня есть список тегов span, которые запускают событие mouseover, которое обновляет атрибут src и вставляет следующее изображение. Проблема, с которой я сталкиваюсь, заключается в том, что если пользователь быстро прокручивает несколько элементов управления, то анимациястановится очень нервным и выглядит плохо.Ниже мой текущий код:
$("#list .client").mouseover(function(){
var imgSrc = $(this).attr('rel');
var image1 = $("#clientImage1");
var image2 = $("#clientImage2");
if(image1.is(":visible")){
image2.attr('src', imgSrc);
image2.stop(true, true).show("slide", { direction: "down" }, 400);
image1.stop(true, true).hide("slide", { direction: "up" }, 400);
//image1.hide();
}
else{
image1.attr('src', imgSrc);
image1.stop(true, true).show("slide", { direction: "down" }, 400);
image2.stop(true, true).hide("slide", { direction: "up" }, 400);
}
//console.log("Img Source: " + imgSrc);
});
Что я хотел бы сделать, это добавить задержку, если в данный момент анимация еще продолжается.Я не хочу ставить в очередь функции, просто выполнить последнюю вызванную при последней наведении мыши.Я предполагаю, что это как-то связано с SetTimeout, но меня немного смущает, как этого добиться.
Есть идеи?
Спасибо!
Редактировать:
Большое спасибо за вашу помощь, наконец-то заставил его работать с hoverIntent!Рабочий код:
$(document).ready(function(){
$("#clientImage2").hide();
$("#list .client").hoverIntent(config);
});
var config = {
over: slideShow, // function = onMouseOver callback (REQUIRED)
timeout: 600, // number = milliseconds delay before onMouseOut
out: doNothing // function = onMouseOut callback (REQUIRED)
};
function slideShow() {
var imgSrc = $(this).attr('rel');
var image1 = $("#clientImage1");
var image2 = $("#clientImage2");
if(image1.is(":visible")){
image2.attr('src', imgSrc);
image2.stop(true, true).show("slide", { direction: "down" }, 600);
image1.stop(true, true).hide("slide", { direction: "up" }, 600);
}
else{
image1.attr('src', imgSrc);
image1.stop(true, true).show("slide", { direction: "down" }, 600);
image2.stop(true, true).hide("slide", { direction: "up" }, 600);
}
}
function doNothing(){}