Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Zoom" a browser window/view with JavaScript?

We can zoom in and out scrolling with pressing ctrl.

But I want to do that using jQuery or JavaScript. Is is possible?

like image 867
user1241761 Avatar asked Mar 21 '12 03:03

user1241761


People also ask

How do I zoom out a Web page using JavaScript?

style. zoom = "80%"; to set the zoom style of the body element to '80%' to set the zoom of the page to 80%.

Can JavaScript detect the browser zoom level?

Method 1: Using outerWidth and innerWidth Property: It is easier to detect the zoom level in webkit browsers like Chrome and Microsoft Edge. This method uses the outerWidth and innerWidthproperties, which are the inbuilt function of JavaScript.

How do I zoom in and Unzoom my browser?

To manually adjust the settings, use the Ctrl key and “+” or “-” combos to increase or decrease the page magnification. If you are using a mouse, you can hold down the keyboard Ctrl key and use the mouse wheel to zoom in or out.


2 Answers

Since you have tagged in jquery also (though written only js in the question title) I would add this answer

You can add the following css to a webpage to zoom a browser window

body {
   -moz-transform: scale(0.8, 0.8);
   zoom: 0.8;
   zoom: 80%;
}

So your jquery becomes

$(document).ready(function(){
  $('body').css('zoom','80%'); /* Webkit browsers */
  $('body').css('zoom','0.8'); /* Other non-webkit browsers */
  $('body').css('-moz-transform',scale(0.8, 0.8)); /* Moz-browsers */
});

Dont worry about any cross-browser since any incomprehensible css property would be avoided by the browser.

like image 160
akki Avatar answered Oct 05 '22 06:10

akki


Checkout this jsfiddle. Something you may use but it's not exact function like browser zoom-in zoom-out.

$('#zoom-in').click(function() {
   updateZoom(0.1);
});

$('#zoom-out').click(function() {
   updateZoom(-0.1);
});


zoomLevel = 1;

var updateZoom = function(zoom) {
   zoomLevel += zoom;
   $('body').css({ zoom: zoomLevel, '-moz-transform': 'scale(' + zoomLevel + ')' });
}
like image 24
Jimba Tamang Avatar answered Oct 05 '22 07:10

Jimba Tamang