Skip to content

Commit

Permalink
Add detection for support of scrollToOptions mode of window.scrollTo() (
Browse files Browse the repository at this point in the history
  • Loading branch information
chris13524 authored Aug 27, 2020
1 parent 55f3f36 commit ef28146
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
34 changes: 34 additions & 0 deletions feature-detects/scrolltooptions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*!
{
"name": "scrollToOptions dictionary",
"property": "scrolltooptions",
"caniuse": "mdn-api_scrolltooptions",
"notes": [{
"name": "MDN docs",
"href": "https://developer.mozilla.org/en-US/docs/Web/API/Window/scrollTo"
}],
"authors": ["Oliver Tušla (@asmarcz)", "Chris Smith (@chris13524)"]
}
!*/
define(['Modernizr', 'createElement', 'getBody'], function (Modernizr, createElement, getBody) {
Modernizr.addTest('scrolltooptions', function () {
var body = getBody();
var returnTo = window.pageYOffset;
var needsFill = body.clientHeight <= window.innerHeight;
if (needsFill) {
var div = createElement('div');
div.style.height = (window.innerHeight - body.clientHeight + 1) + 'px';
div.style.display = 'block';
body.appendChild(div);
}
window.scrollTo({
top: 1
});
var result = window.pageYOffset !== 0;
if (needsFill) {
body.removeChild(div);
}
window.scrollTo(0, returnTo);
return result;
});
});
1 change: 1 addition & 0 deletions lib/config-all.json
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@
"requestanimationframe",
"script/async",
"script/defer",
"scrolltooptions",
"serviceworker",
"speech/speech-recognition",
"speech/speech-synthesis",
Expand Down

0 comments on commit ef28146

Please sign in to comment.