Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I stop my fixed navigation from moving like this when the virtual keyboard opens in Mobile Safari?

I understand that mobile safari has a lot of bugs around fixed elements, but for the most part I've managed to get my layout working correctly until I added a much needed text input to the fixed navigation at the bottom. Now when the user focuses on the text input element and the virtual keyboard appears, my navigation, which is otherwise always fixed at the bottom of the page, jumps up to a really strange spot in the middle of the page.

enter image description here

I'd add some of my code to this post, but I wouldn't be sure where to start. That navigation is fixed at the bottom and positioned to the left and bottom 0, and 100% width. From there, I don't know what's going on, I can only assume it's a mobile safari bug.

It also appears to lose it's position fixed and become relative, only while the text input element is focused on and the virtual keyboard is open.

like image 622
Eric Avatar asked Mar 07 '13 13:03

Eric


People also ask

How do you make fixed content go above IOS keyboard?

To force it work the same way as Mobile Chrome, you have to use position: absolute, height: 100% for the whole page or a container for your pseudo-fixed elements, intercept scroll, touchend, focus, and blur events. The trick is to put the tapped input control to the bottom of screen before it activates focus.

Can you change the iPhone keyboard?

Go to Settings > General > Keyboard. Tap Keyboards, then do any of the following: Add a keyboard: Tap Add New Keyboard, then choose a keyboard from the list. Repeat to add more keyboards.


1 Answers

http://dansajin.com/2012/12/07/fix-position-fixed/ this is one of the solutions proposed. Seems worth a shot.

In short: set fixed elements to position:absolute when any input is focused and reset them when that element is blurred

.header {      position: fixed;  }  .footer {      position: fixed;  }  .fixfixed .header,  .fixfixed .footer {      position: absolute;  }  

and

if ('ontouchstart' in window) {     /* cache dom references */      var $body = $('body');       /* bind events */     $(document)     .on('focus', 'input', function() {         $body.addClass('fixfixed');     })     .on('blur', 'input', function() {         $body.removeClass('fixfixed');     }); } 
like image 128
Sujesh Arukil Avatar answered Sep 20 '22 13:09

Sujesh Arukil