Jump to content
This forum will be closing down. Please move to the respective dedicated project forums.

How to prevent zooming with browser?


ShotgunJed
 Share

Recommended Posts

Zooming with the browser seems to affect the size of the game.

This is my code here:

window.onresize = function (event) {
  var w = window.innerWidth;
  var h = window.innerHeight;
  renderer.view.style.width = w + "px";
  renderer.view.style.height = h + "px";
  renderer.resize(w, h);
}

How do I make it so regardless of how much the user is zoomed in their browser, the values w and h shouldn't change? (If the user resizes their window, it should change though)

Link to comment
Share on other sites

var resolution = window.devicePixelRatio;
var w = window.innerWidth;
var h = window.innerHeight;
var w2 = Math.round(w * resolution);
var h2 = Math.round(h * resolution);
renderer.view.style.width = w + "px";
renderer.view.style.height = h + "px";
renderer.resize(w2, h2);

w2 and h2 will be the same if user zooms.

I also recommend to abandon it, and allow users to zoom.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...