Re: [spec-reviews] CSSOM View document.scrollingElement (#51)

Some more background on why moving this from user code to the browser might be a good thing: feature-detecting the scrolling element (especially if you need to get the edge cases right, which is what libraries usually aim for) is costly. One way is to actually scroll the document:

```js
var $scrollElement = (function() {
  var $html = $(document.documentElement);
  var $body = $(document.body);
  var bodyScrollTop;
  if ($html.scrollTop()) {
    return $html;
  } else {
    bodyScrollTop = $body.scrollTop();
    // Scrolling the body doesn’t do anything.
    if ($body.scrollTop(bodyScrollTop + 1).scrollTop() == bodyScrollTop) {
      return $html;
    } else {
      // We actually scrolled, so undo it.
      return $body.scrollTop(bodyScrollTop);
    }
  }
}());
```

The terribleness might explain why so many (e.g. Google, Facebook) opt to UA sniff instead, which is more performant but leads to compat problems (@rbyers knows all about them).

---
Reply to this email directly or view it on GitHub:
https://github.com/w3ctag/spec-reviews/issues/51#issuecomment-93843251

Received on Thursday, 16 April 2015 21:26:39 UTC