V
V
Vasya2016-10-28 19:06:52
iPhone
Vasya, 2016-10-28 19:06:52

Zoom in on iPhone input field focus?

(function(){
  // Выполняем код только на мобильных браузерах (на всякий случай)
  if (typeof(window.orientation) !== 'undefined')
  {
    // Функция взята отсюда: https://makandracards.com/makandra/13743-detect-effective-horizontal-pixel-width-on-a-mobile-device-with-javascript
    function getDeviceWidth()
    {
      var deviceWidth = window.orientation == 0 ? window.screen.width : window.screen.height;
      // iOS returns available pixels, Android returns pixels / pixel ratio
      // http://www.quirksmode.org/blog/archives/2012/07/more_about_devi.html
      if (navigator.userAgent.indexOf('Android') >= 0 && window.devicePixelRatio)
        deviceWidth = deviceWidth / window.devicePixelRatio;

      return deviceWidth;
    }

    var deviceWidth = getDeviceWidth();
    var maxWidth = 640;

    if (deviceWidth < maxWidth)
    {
      var viewportmeta = document.querySelector('meta[name="viewport"]');
      // Мои эксперименты на iPad 2 показали, что device-width всегда содержит значение ширины
      // экрана в книжной (portrait) ориентации (т.е. даже, если устройство находится в
      // альбомной (landscape) ориентации). Это же утверждалось в некоторых найденных мною статьях.
      if (window.orientation == 0 || window.orientation <= 180)
        viewportmeta.content = 'width=device-width';
      else
        viewportmeta.content = 'width=device-height';
    }
    else
      viewportmeta.content = maxWidth;
  }
})();

Guys, help me figure out the problem, my site should work from 640 pc, with the help of this script on small screens the scale starts as it should, but if you start typing text in the input fields, then the scale increases, how to turn it off does anyone know?

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