M
M
Mikhail Makarov2016-02-24 07:56:24
Android
Mikhail Makarov, 2016-02-24 07:56:24

Scaling the game for different devices. What's wrong with android?

I write toys in HTML5 of a fixed size for desktop and mobile platforms. The fact that the zoom property is not defined in Firefox in CSS does not really bother me now. I'm worried about why screen sizes are determined correctly in desktop chrome, but not in mobile ... $(window).height() gives the hell out of it, window.screen.availHeight is already better, but still does not save the day . Please look at my script and tell me what I'm doing wrong.

$(document).ready(function() {
  function applyScale() {
    var scaleFactor = 1, scaleFactorX = 1, scaleFactorY = 1;
    var width, height;

    // why adnroid is so strange?
    if (isAndroid()) {
      var width = window.screen && window.screen.availHeight || $(window).width();
      var height = window.height && window.screen.availWidth || $(window).height();
    } else {
      var width = $(window).width();
      var height = $(window).height();
    }

    if (width < 1450) {
      scaleFactorX = width / 1450;
    }

    if (height < 1024) {
      scaleFactorY = height / 1024;
    }

    scaleFactor = scaleFactorX < scaleFactorY ? scaleFactorX : scaleFactorY;

    if (scaleFactor < 0.1) {
      scaleFactor = 0.1;
    }

    $('body').css('zoom', scaleFactor);
  }

  $(window).resize(function() {
    applyScale();
  });

  applyScale();
});

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question