     previousTimestamp = null
     animatorId = null
 
-    advanceAnimation = ->
-      animatorId = requestAnimationFrame animate
-
-    cancelAnimation = ->
-      cancelAnimationFrame animatorId
-
-    animate = (timestamp) ->
+    advanceAnimation = -> animatorId = requestAnimationFrame animate
+    cancelAnimation = -> cancelAnimationFrame animatorId
+
+    animate = (timestamp) =>
       previousTimestamp ?= timestamp
-
-      if timestamp == previousTimestamp
-        return advanceAnimation()
+      return advanceAnimation() if timestamp == previousTimestamp
 
       # The elapsed time is typically about 16ms.
       elapsed = timestamp - previousTimestamp

    return if @lastEvent?.repeat

    activationTime = ++@time

    isMyKeyStillDown = =>
      @time == activationTime and @keyIsDown

    # Store amount's sign and make amount positive; the logic is clearer when amount is positive.
    sign = Math.sign amount

  axisName = scrollProperties[direction].axisName
  before = element[axisName]
  element[axisName] += amount
  element[axisName] == amount + before

# Test whether element should be scrolled.
shouldScroll = (element, direction) ->
