나는 crossfading하여 많은 이미지를 움직이게하는 간단한 함수를 가지고있다. 간단한 배너 회전. 함수를 설정하여 animateSlideshow("play")
을 호출하면 타임 아웃을 설정하고 애니메이션을 시작해야하며 animateSlideshow("stop")
을 호출해야합니다.jQuery setTimeout issue
그러나 stop을 호출하면 애니메이션이 한 번 더 발생합니다. 이 하나의 추가 애니메이션의 원인은 무엇이며 어떻게 처리 할 수 있습니까?
이 바닥
function prevSlide(e){
if(curHashIndex !== 0){
$(prevBtn).off();
// Stop the current slideshow
animateSlideshow("stop");
// Reset the current slideshow
$("li.active .rightSlide > li").fadeOut(600).eq(0).fadeIn(600).addClass("actvImg");
$(".rightSlides").animate({
"left" : '+=345'
}, 600, function(){
$(prevBtn).on('click', prevSlide);
});
$(".leftSlides").animate({
"left" : '+=417'
}, 600);
// Activate the new slide
$(".rightSlides li.active").removeClass("active").prev().addClass("active");
activeSlide = $(".rightSlides li.active");
total = $(".rightSlides li.active .rightSlide > li").length;
// Start slideshow on the new slide
var delay = setTimeout(animateSlideshow("play"), 10000);
updateHash();
}
}
function animateSlideshow(action){
if(action === "play"){
$(activeSlide).data('animateSlideshow',
setTimeout(function(){
if($(actvImg).index() === total - 1){
$(actvImg).fadeOut(animationSpeed).removeClass("actvImg").siblings().eq(0).fadeIn(animationSpeed).addClass("actvImg");
}else{
$(actvImg).fadeOut(animationSpeed).removeClass("actvImg").next().fadeIn(animationSpeed).addClass("actvImg");
}
actvImg = $(".rightSlides li.active .rightSlide > li.actvImg");
actvImgIndx = $(actvImg).index();
updateBreadcrumbs();
animateSlideshow("play")
}, animationTimeout)
);
}else{
clearTimeout($(activeSlide).data('animateSlideshow'));
};
};
실제로 나에게는 동일한 결과가있었습니다. 처음에는 간격으로 함수를 작성했습니다. –
최소한 setTimeout()을 사용하여 데이터를 리 바인드하지 않아야합니다.이 함수를 호출하는 것이 무엇인지 알 필요가 있거나이 문제가 나타나는 특정 브라우저가 있는지 알아야 할 수도 있습니다.이 함수는 예상대로 작동해야합니다. – Scottux
첫 번째 게시물을 전화를 걸 수있는 기능으로 업데이트했습니다. –