Use `document.scrollingElement` for mobile scrolls

- Set `document.scrollingElement` as the scrolling element
  for scrolling to anchors when the app is mobile mode
  to enhance support in newer browsers.
  The CSS View Module spec considers `document.documentElement`/`<html>`
  to be the standard scrolling element
  and that is what appears to be used in the latest Firefox and Chrome.
  However, some older browsers and even the current Safari
  use `document.body` as the scrolling element
  which is why I suspect the original code used `document.body`.
  Since some browsers scroll on different elements,
  `document.scrollingElement` exists
  so the browser can tell us what to use
  for scrolling to anchors work for all modern browsers.
  Since `document.scrollingElement` is undefined in older browsers,
  `document.body` is available as fallback mobile scrolling element.
pull/821/head
Grant Bourque 7 years ago
parent 2ec5018bff
commit 3a446f1f9d
No known key found for this signature in database
GPG Key ID: 1AB8D5DDBB061139

@ -19,7 +19,10 @@ class app.views.Content extends app.View
after: 'afterRoute' after: 'afterRoute'
init: -> init: ->
@scrollEl = if app.isMobile() then document.body else @el @scrollEl = if app.isMobile()
(document.scrollingElement || document.body)
else
@el
@scrollMap = {} @scrollMap = {}
@scrollStack = [] @scrollStack = []

Loading…
Cancel
Save