(function () {
  var scrollIncrement = 4
  var scrollTop = 0
  var page

  function clearSchedule(x) {
    clearTimeout(x)
  }

  function setSchedule(x) {
    setTimeout(x, 16)
  }

  function schedule(callback) {
    var frameId

    (function () {
      clearSchedule(frameId)
      frameId = setSchedule(callback)
    }())
  }

  function calculateScrollTop(el) {
    var y = 0
    var node = el

    while (node) {
      y += node.offsetTop
      node = node.offsetParent
    }

    return y
  }

  var scrollIncrement = 4

  function animateScrollTop(top, n) {
    var n = n || 1

    schedule(function () {
      var diff = top - page.scrollTop
      var increment = scrollIncrement * n

      if (diff) {
        if (Math.abs(diff) < increment) {
          page.scrollTop += diff
        } else if (diff > 0) {
          page.scrollTop += increment
        } else {
          page.scrollTop -= increment
        }

        animateScrollTop(top, ++n)
      }
    })
  }

  function scrollIntoView(event) {
    var el = document.getElementById(event.currentTarget.getAttribute('href').substr(1))
    animateScrollTop(calculateScrollTop(el) - 120)

    // XXX: When Chrome 70.0.3538.77 navigates to an internal anchor (#),
    // it breaks the page layout so we don’t want to do that.
    event.preventDefault()
  }

  function scrollUp(event) {
    animateScrollTop(calculateScrollTop(document.getElementById('use-cases')))
    event.preventDefault()
  }

  function ready() {
    page = document.documentElement

    if (typeof requestAnimationFrame === 'function') {
      clearFrame = cancelAnimationFrame
      setFrame = requestAnimationFrame
    }

    var anchors = document.getElementsByTagName('a')

    for (let i = 0, n = anchors.length; i < n; ++i) {
      var anchor = anchors[i]
      var href = anchor.getAttribute('href')
      var classes = (anchor.className || '').split(/\s+/)

      if (href && href[0] === '#') {
        anchor.addEventListener('click', scrollIntoView)
      } else if (classes.indexOf('action--scroll-up') > -1) {
        anchor.addEventListener('click', scrollUp)
      }
    }
  }

  (function check() { /complete/.test(document.readyState) ? ready() : setTimeout(check) }())
}())
@@ -621,35 +621,69 @@
 var 
-diff = top - page.scrollTop
+currentY = window.pageYOffset%0A      var diff = top - currentY
 %0A   
@@ -731,22 +731,34 @@
      if 
+(Math.floor
 (diff)
+)
  %7B%0A     
@@ -796,36 +796,38 @@
 nt) %7B%0A          
-page
+window
 .scrollTop += di
@@ -823,17 +823,28 @@
 llTo
-p
+(0, currentY
  +
-=
  diff
+)
 %0A   
@@ -873,36 +873,38 @@
  0) %7B%0A          
-page
+window
 .scrollTop += in
@@ -900,12 +900,22 @@
 llTo
-p
+(0, currentY
  +
-=
  inc
@@ -912,32 +912,34 @@
 entY + increment
+)%0A
 %0A        %7D else 
@@ -950,20 +950,22 @@
         
-page
+window
 .scrollT
@@ -969,12 +969,22 @@
 llTo
-p
+(0, currentY
  -
-=
  inc
@@ -989,16 +989,17 @@
 ncrement
+)
 %0A       
@@ -1665,20 +1665,23 @@
    clear
-Fram
+Schedul
 e = canc
@@ -1706,20 +1706,23 @@
      set
-Fram
+Schedul
 e = requ
@@ -2308,12 +2308,13 @@
 k) %7D())%0A%7D())
+%0A

refactor animateScrollTop method to scroll on safari with pageYOffset. Math.floor added so function does not run indefinitely