Building an online Solitaire game means moving a lot of cards around, often at the same time, and almost always in response to a click or drag. That situation forced a library decision, and the criteria that drove it were smoothness, performance, writing convenience and browser support. Convenience even outweighed a small amount of performance cost, since maintainable code was a real requirement for someone with a design-heavy background working in JavaScript.

The CSS-or-JavaScript question first

CSS animation libraries are abundant and often perform well, and sequenced effects with completion callbacks are achievable in pure CSS. What pushed the decision toward JavaScript was ergonomics: the work gets split across files in ways that become hard to follow as complexity grows.

A CSS version of a simple sequence requires the keyframes to be defined and bound to a class in the stylesheet:

.card.move {
  animation : move 2s;
}

@keyframes move {
  0% { left: 0 }
  50% { left: 100px }
  100% { left: 0 }
}

The trigger and the completion listener then live in JavaScript:

var cardElement = document.getElementsByClassName("card")[0];
var statusElement = document.getElementsByClassName("status")[0];

cardElement.classList.add("move");
statusElement.innerHTML = "Animating"

var animationEndCallback = function() {
  cardElement.classList.remove("move");
  statusElement.innerHTML = "Inactive"
}

cardElement.addEventListener("webkitAnimationEnd", animationEndCallback);
cardElement.addEventListener("oAnimationEnd", animationEndCallback); 
cardElement.addEventListener("antionend", animationEndCallback);

jQuery's built-in helpers can express the same animation entirely in one place:

$(".status").text("Animating")
$( ".card" ).animate({
  left: "100px"
}, 1000);
$( ".card" ).animate({
  left: 0
}, 1000, function() {
  $(".status").text("Inactive")
});

The visuals match; the maintenance story does not. Keeping behaviour in a single location made a JavaScript-based approach the more attractive route, though jQuery itself felt like a shaky foundation to build on despite its continued widespread use. The goal became a library written specifically for heavy animation work.

Narrowing the field

Two platform-level options were considered and set aside. The Web Animations API can produce complex staggered animations with CSS-equivalent performance and no external dependency, but browser support is incomplete. The <canvas> element renders animation as raster, which is fast, but it renders essentially as an image in the DOM, ruling out the pixel precision the project needed.

That left established libraries, and the shortlist came down to Anime.js and GSAP. Both handle complex animation well, both have solid performance reputations, and both have large, active communities — an important point, since a library needs somewhere to ask for help and should not be at risk of abandonment. Anime had more than 42,000 GitHub stars at the time; GSAP was already long established and battle-tested.

Sequencing a card flip

The recurring animation in Solitaire — a card moves, then flips over — was used to test both candidates. Both produced smooth results, and both offer a timeline() function that makes sequencing straightforward. The Anime.js implementation:

var timeline = anime.timeline({
  begin: function() {
    $(".status").text("Animating")
  },
  complete: function() {
    $(".status").text("Inactive")
  }
});

timeline.add({
  targets: '.card',
  left: [0, 300],
  easing: 'easeInOutSine',
  duration: 500
}).add({
  targets: '.card .back',
  rotateY: [0, 90],
  easing: 'easeInSine',
  duration: 200
}).add({
  targets: '.card .front',
  rotateY: [-90, 0],
  easing: 'easeOutSine',
  duration: 200
})

The sequence comes from appending steps: move the card, rotate the back image 90 degrees so it leaves view, then rotate the front image 90 degrees so it enters view. Anime's timeline() ships with beginning and ending callbacks.

The GSAP equivalent follows the same shape:

var timeline = gsap.timeline({
  onStart: function() {
    $(".status").text("Animating")
  },
  onComplete: function() {
    $(".status").text("Inactive")
  }
});

timeline.fromTo(".card", {
  left: 0
}, {
  duration: 0.5,
  left: 300
}).fromTo(".card .back", {
  rotationY: 0
}, {
  rotationY: 90,
  ease: "power1.easeIn",
  duration: 0.2
}).fromTo(".card .front", {
  rotationY: -90
}, {
  rotationY: 0,
  ease: "power1.easeOut",
  duration: 0.2
})

Functionally the two were close enough to call a tie, with GSAP's syntax reading as somewhat more elaborate. Something else had to break it.

What decided it: behaviour under load

Animation jank in a card game has a direct effect on how fun it is to play, and that performance could not be judged until the game existed. GSAP's published stress test, which compared several animation libraries including Anime, gave a usable signal: on a heavy animation GSAP reached upwards of 26 frames per second where Anime topped out at 19.

PriorityAnimeGSAP
Smooth animations✅✅
Performance✅✅
Convenience✅✅
Browser support✅✅

Project activity reinforced the point. Both libraries have been around for years, but Anime's repository had been largely dormant for a couple of years while GSAP had commits within the previous couple of months — and the performance emphasis came through in GSAP's forums and documentation as well.

GSAP was the choice, and the decision held up in use. One question worth putting to other front-end developers: are there priorities beyond these — accessibility, for instance — that would change the calculation on a project of this kind?