Skip to content

Instantly share code, notes, and snippets.

@leMaur
Last active October 20, 2018 18:54
Show Gist options
  • Select an option

  • Save leMaur/a65c4ec7eb5ede963ef4c66821ff1ed6 to your computer and use it in GitHub Desktop.

Select an option

Save leMaur/a65c4ec7eb5ede963ef4c66821ff1ed6 to your computer and use it in GitHub Desktop.
(function () {
// set default ratio value
let ratio = 1;
// use systemXDPI and logicalXDPI if available
if (window.screen.systemXDPI !== undefined
&& window.screen.logicalXDPI !== undefined
&& window.screen.systemXDPI > window.screen.logicalXDPI) {
ratio = window.screen.systemXDPI / window.screen.logicalXDPI;
}
// use devicePixelRatio if available
else if (window.devicePixelRatio !== undefined) {
ratio = window.devicePixelRatio;
}
if (typeof define === 'function' && define.amd) {
define(ratio.toFixed(1));
} else {
window.DPR = ratio.toFixed(1);
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment