Skip to content

Instantly share code, notes, and snippets.

@zacharyblank
Last active August 29, 2015 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zacharyblank/8c510b3675540a019935 to your computer and use it in GitHub Desktop.
Save zacharyblank/8c510b3675540a019935 to your computer and use it in GitHub Desktop.
Watch for screen resolution change
'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