mirror of
https://github.com/pcottle/learnGitBranching.git
synced 2025-06-29 09:20:03 +02:00
zoom level continue
This commit is contained in:
parent
f60b97307a
commit
7750bae1b4
2 changed files with 66 additions and 3 deletions
|
@ -1,10 +1,31 @@
|
|||
var _ = require('underscore');
|
||||
|
||||
var warnOnce = true;
|
||||
|
||||
function detectZoom() {
|
||||
/**
|
||||
* Note: this method has only been tested on Chrome
|
||||
* but seems to work. A much more elaborate library is available here:
|
||||
* https://github.com/yonran/detect-zoom
|
||||
* but seems to return a "2" zoom level for my computer (who knows)
|
||||
* so I can't use it. The ecosystem for zoom level detection is a mess
|
||||
*/
|
||||
if (!window.outerWidth || !window.innerWidth) {
|
||||
if (warnOnce) {
|
||||
console.warn("Can't detect zoom level correctly :-/");
|
||||
warnOnce = false;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
return window.outerWidth / window.innerWidth;
|
||||
}
|
||||
|
||||
var setupZoomPoll = function(callback, context) {
|
||||
var currentZoom = 0;
|
||||
|
||||
setInterval(function() {
|
||||
var newZoom = window.outerWidth / window.innerWidth;
|
||||
var newZoom = detectZoom();
|
||||
if (newZoom !== currentZoom) {
|
||||
currentZoom = newZoom;
|
||||
callback.apply(context, [newZoom]);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue