I created a little game in Canvas, but I have a problem. Some users who have the default zoom set to something other than 100% can't see the entire game page.
I have tried using this CSS:
zoom: 100%;
This HTML
<meta name="viewport" content="initial-scale=1.0 , minimum-scale=1.0 , maximum-scale=1.0" />
And this JS:
style="zoom: 75%"
Any ideas how to programatically set the page zoom?
JavaScript can be used to manipulate an HTML element's style property to create a zoom-in and zoom-out effect. To do this, simply access the width attribute using the style property and increase it or decrease it according to the requirement.
By default, Chrome sets the zoom level to 100%. 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.
Currently there is no way to detect the zoom level with Javascript reliably.
You can set zoom
property on page load
document.body.style.zoom = 1.0
But, zoom
is not a standard property for all browsers, I recommend using transform
instead.
var scale = 'scale(1)'; document.body.style.webkitTransform = scale; // Chrome, Opera, Safari document.body.style.msTransform = scale; // IE 9 document.body.style.transform = scale; // General
http://jsfiddle.net/5RzJ8/
You can reset the code with this:
$("input, textarea").focusout(function(){ $('meta[name=viewport]').remove(); $('head').append('<meta name="viewport" content="width=device-width, maximum-scale=1.0, user-scalable=0">'); $('meta[name=viewport]').remove(); $('head').append('<meta name="viewport" content="width=device-width, initial-scale=yes">' ); });
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