Advertisement
NonplayerCharacter

Get devicePixelRatio in main browsers

May 4th, 2017
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // http://stackoverflow.com/questions/5063489/how-can-you-get-the-css-pixel-device-pixel-ratio
  2. window.getDevicePixelRatio = function () {
  3.     var ratio = 1;
  4.     // To account for zoom, change to use deviceXDPI instead of systemXDPI
  5.     if (window.screen.systemXDPI !== undefined && window.screen.logicalXDPI !== undefined && window.screen.systemXDPI > window.screen.logicalXDPI) {
  6.         // Only allow for values > 1
  7.         ratio = window.screen.systemXDPI / window.screen.logicalXDPI;
  8.     }
  9.     else if (window.devicePixelRatio !== undefined) {
  10.         ratio = window.devicePixelRatio;
  11.     }
  12.     return ratio;
  13. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement