Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to trigger iPhone zoom-out after auto zoom-in to a form?

I have a web form that uses jQuery to submit a search. The form itself doesn't fire the submit event because I catch that and drop it (this is all part of a much larger and more complex form and I'm using progressive enhancement to add this functionality).

On the iPhone, the browser automatically zooms in to my search input as soon as it is focused. On an "enter" keyup event, the search is executed via javascript, and I blur the input which dismisses the on screen iPhone keyboard, but the browser stays zoomed in to the input area.

Is there a way to programatically trigger zooming out again back to the initial viewport area via javascript?

EDIT: there's no redirect on search execution which would normally reset the viewport when the new page loads - everything happens on one page here.

like image 268
bbodien Avatar asked May 17 '11 11:05

bbodien


People also ask

Why does my phone keep zooming in and I cant Zoom out?

Select “Accessibility“. Choose “Vision“. Scroll down and select “Magnification gestures“. Set the slider at the upper-right part of the screen to “Off“.

How do I stop my iPhone from zooming in input focus?

If you enlarge the field by increasing all dimensions by 16 / 12 = 133.33%, then reduce using scale() by 12 / 16 = 75%, the input field will have the correct visual size (and font size), and there will be no zoom on focus.

Why does my iPhone Zoom in automatically?

Your iPhone is stuck zoomed in because an accessibility feature called Zoom is turned on in Settings. Zoom makes it easier for people with low vision to use their iPhones by allowing them to zoom in on certain parts of the screen.


2 Answers

If the input's font-size is a minimum of 16px the zoom in will not be triggered to begin with.

like image 132
whistler Avatar answered Sep 20 '22 15:09

whistler


I've used the following successfully.

$('input, select, textarea').on('focus blur', function(event) {     $('meta[name=viewport]').attr('content', 'width=device-width,initial-scale=1,maximum-scale=' + (event.type == 'blur' ? 10 : 1));   });  <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <head>   <meta name="viewport" content="width=device-width,initial-scale=1" /> </head>  <body>   <input id="input" type="text" placeholder="Type here..." /> </body> 
like image 28
Shayna Symons Avatar answered Sep 18 '22 15:09

Shayna Symons