We can zoom in and out scrolling with pressing ctrl.
But I want to do that using jQuery or JavaScript. Is is possible?
style. zoom = "80%"; to set the zoom style of the body element to '80%' to set the zoom of the page to 80%.
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.
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.
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.
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 + ')' });
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With