     amount
 
 # Perform a scroll. Return true if we successfully scrolled by the requested amount, and false otherwise.
-performScroll = (element, axisName, amount) ->
+performScroll = (element, direction, amount) ->
+  axisName = scrollProperties[direction].axisName
   before = element[axisName]
   element[axisName] += amount
   amount == element[axisName] - before

      time == activationTime

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

    # Duration in ms. Allow a bit longer for longer scrolls.

# Instead, we scroll the element by 1 or -1 and see if it moved (then put it back).
# Bug verified in Chrome 38.0.2125.104.
isScrollPossible = (element, direction, amount, factor) ->
  # amount, 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, we're definitely scrolling
  # backwards, so a delta of -1 will do.
  delta = factor * getDimension(element, direction, amount) || -1
  delta = Math.sign delta # 1 or -1
  performScroll(element, direction, delta) and performScroll(element, direction, -delta)

# Find the element which we should and can scroll (or document.body).
findScrollableElement = (element, direction, amount, factor = 1) ->
  while element != document.body and
    not (isScrollPossible(element, direction, amount, factor) and shouldScroll(element, direction))
      element = element.parentElement || document.body
