Last active
August 29, 2015 14:03
-
-
Save zacharyblank/8c510b3675540a019935 to your computer and use it in GitHub Desktop.
Watch for screen resolution change
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict' | |
module.exports = function() { | |
if ( ! watchers) var watchers = []; | |
var watchResolution = (function watchResolution() { | |
var devicePixelRatio = window.devicePixelRatio; | |
setTimeout(function() { | |
if (devicePixelRatio != window.devicePixelRatio) { | |
devicePixelRatio = window.devicePixelRatio; | |
for (var i = 0; i < watchers.length; i++) { | |
watchers[i](devicePixelRatio) | |
}; | |
} | |
watchResolution(); | |
}) | |
})() | |
return { | |
change: function(watcher) { | |
watchers.push(watcher); | |
watcher(window.devicePixelRatio); | |
} | |
} | |
}() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment