animation-direction: alternate
를 사용
데모. 무한한 접근법을 원한다면 더 깨끗하다고 생각합니다. Here's the fiddle.
표시 추가 : 없음;
.e {display:none;}
그리고 jQuery를 선택 $('.e')
에서 제공하는 요소의 컬렉션을 처리하는 즉시 호출 기능 식 (인생)을 사용 : 전자 클래스. 응답
(function($){
(function fadeNext(collection){
collection.eq(0).fadeIn(1000, function(){
(collection=collection.slice(1)).length
&& fadeNext(collection)
});
})($('.e'))
})(jQuery)
편집 댓글을 :
은 무한에주의하십시오. clearTimout() 호출을 추가하여 더 이상 필요하지 않다고 판단한 후에 실행을 중지하고자 할 수 있습니다. 여기에 업데이트 된 JS 코드 (updated fiddle)입니다 :
(function($){
var el = $('.e');
var animationLength = 1000;
var duration = el.length * animationLength + animationLength;
var clearAfter = 100;
var animation;
function fadeNext(collection){
collection.eq(0).fadeIn(animationLength, function(){
(collection=collection.slice(1)).length
&& fadeNext(collection)
});
}
function play(){
fadeNext(el);
animation = setTimeout(function(){
el.hide();
play();
}, duration);
}
play();
setTimeout(function(){
clearTimeout(animation);
}, duration * clearAfter);
})(jQuery)
까지 내가 거기에 애니메이션이 완료되면 다음 하나를 시작할 때 알아낼 수 있도록 CSS에서 콜백 함수가 없다는 것을 알 수 있습니다. – Billy