Skip to content

Instantly share code, notes, and snippets.

@tk-o
Last active December 15, 2019 09:32
Show Gist options
  • Save tk-o/afb6d638d730d8e9ce278e3df2b15552 to your computer and use it in GitHub Desktop.
Save tk-o/afb6d638d730d8e9ce278e3df2b15552 to your computer and use it in GitHub Desktop.
supports position: sticky in javascript #learninpublic
// es-5 compatible
function supportsPositionSticky() {
var element = document.createElement('div');
return ['', '-o-', '-webkit-', '-moz-', '-ms-'].filter(function(prefix) {
element.style.position = prefix + 'sticky';
return element.style.position === 'sticky';
}).length !== 0;
}
// es-next compatible
function supportsPositionSticky() {
const element = document.createElement('div');
return ['', '-o-', '-webkit-', '-moz-', '-ms-'].some(prefix => {
element.style.position = prefix + 'sticky';
return element.style.position === 'sticky';
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment