Time for action – defining a post-animation callback

Next we need a function that we can execute each time an animation ends:

function postAnim(dir) {

  var keyMatch = parseInt(key.match(/\d+$/));

  (parseInt(slide.css("left")) < 0) ? prev.show() : prev.hide();

  (parseInt(slide.css("left")) === -1600) ? next.hide() : next.show();

  if (dir) {
    var titleKey = (dir === "back") ? keyMatch - 1 : keyMatch + 1;
    key = "image" + titleKey;
  }

  container.find("#title").text(details[key].title);

  container.find(".active").removeClass("active");
  container.find("a[href=#" + key + "]").addClass("active");
};

What just happened?

In this second section of code, we define a function that we'll call after an animation ends. This is used for some housekeeping to do various ...

Get jQuery 1.4 Animation Techniques Beginner's Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.