Skip to content

Instantly share code, notes, and snippets.

@slickplaid
Created November 13, 2015 16:17
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 slickplaid/ec6437dabad084c379ed to your computer and use it in GitHub Desktop.
Save slickplaid/ec6437dabad084c379ed to your computer and use it in GitHub Desktop.
var electronScreen = require('screen');
var webFrame = require('web-frame');
var currentZoomLevel;
var defaultZoomLevel = webFrame.getZoomFactor();
var defaultWidth = 1030;
function getZoomLevel() {
var zoomFactor = webFrame.getZoomFactor();
var width = window.innerWidth * zoomFactor;
var zoom = width / defaultWidth;
return zoom;
};
function setZoom() {
var zoom = getZoomLevel();
if(zoom < 1) {
webFrame.setZoomFactor(1);
} else if(zoom > 2) {
webFrame.setZoomFactor(2);
} else {
webFrame.setZoomFactor(zoom);
}
};
var increaseZoom = function(){
currentZoomLevel = currentZoomLevel + 0.25;
webFrame.setZoomFactor(currentZoomLevel);
};
var decreaseZoom = function(){
currentZoomLevel = currentZoomLevel - 0.25;
webFrame.setZoomFactor(currentZoomLevel);
};
var defaultZoom = function(){
currentZoomLevel = defaultZoomLevel;
webFrame.setZoomFactor(currentZoomLevel);
}
$(window).on('resize', setZoom);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment