So far, I agree with @Tom Sarduy's approach and actually recommend it, as it is a one-time creation of HTML elements, but just to give you a different idea, here is what I managed to create quickly.
CSS changes:
.counter .next, .counter .count { position:absolute; } .counter .next { transform:translateY(-12px); left:0; }
JavaScript changes:
//added before your [photos_change] method var counter = $('.counter'); var currentCount = $('<span class="count">1<span/>'); counter.append(currentCount); // //and then inside your [photos_change] event handler var prevCount = $('.count'); currentCount = $('<span class="count next">' + index + '<span/>'); counter.append(currentCount); TweenMax.to(prevCount, dur, { y: -12, opacity: 0, onCompleteParams: [prevCount], onComplete: function (prevCount) { prevCount.remove(); }, ease: Power2.easeOut }); TweenMax.fromTo(currentCount, dur, { y: 12, opacity: 0 }, { y: 0, opacity: 1, ease: Power2.easeOut }); //
So, I think itβs up to you to decide whichever approach you choose, for example, one-time creation of HTML elements at loading, or a click, like the one I suggest.
Sorry for the ugliness of the code, just what I prepared in a hurry. Hope this helps in something though.
source share