       delta = Math.ceil amount * (elapsed / duration) * calibration
       delta = if isKeyStillDown() then delta else Math.max 0, Math.min delta, amount - totalDelta
 
-      if delta and performScroll element, axisName, sign * delta, false
+      if delta and performScroll element, axisName, sign * delta
         totalDelta += delta
-        progressAnimation()
+        advanceAnimation()
       else
-        # We're done. Make one final call of performScroll to check the visibility of the activated element.
-        performScroll element, axisName, 0, true
+        checkVisibility element
         cancelAnimationFrame animatorId
 
-    progressAnimation()
+    advanceAnimation()
 
 Scroller =
   init: (frontendSettings) ->

# Bug verified in Chrome 38.0.2125.104.
isScrollPossible = (element, direction, amount, factor) ->
  axisName = scrollProperties[direction].axisName
  # delta, here, is treated as a relative amount, which is correct for relative scrolls. For absolute scrolls
  # (only gg, G, and friends), amount can be either 'max' or zero. In the former case, we're definitely
  # scrolling forwards, so any positive value will do for delta.  In the latter case, we're definitely
  # scrolling backwards, so a delta of -1 will do.
  delta = factor * getDimension(element, direction, amount) || -1
  delta = delta / Math.abs delta # 1 or -1
  before = element[axisName]
  element[axisName] += delta
  after = element[axisName]
  element[axisName] = before
  before != after

# Find the element which we should and can scroll (or document.body).
findScrollableElement = (element, direction, amount, factor = 1) ->

    duration = Math.max 100, 20 * Math.log amount

    totalDelta = 0
    totalElapsed = 0.0
    calibration = 1.0
    previousTimestamp = null
    animatorId = null

    advanceAnimation = ->
      animatorId = requestAnimationFrame animate

    cancelAnimation = ->
      cancelAnimationFrame animatorId

    animate = (timestamp) ->
      previousTimestamp ?= timestamp

      if timestamp == previousTimestamp
        return advanceAnimation()

      # The elapsed time is typically about 16ms.
      elapsed = timestamp - previousTimestamp
      totalElapsed += elapsed
      previousTimestamp = timestamp

      # The constants in the duration calculation, above, are chosen to provide reasonable scroll speeds for
