Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS iPad Fixed position breaks when keyboard is opened

Fixed position breaks on header when I click on the "Search Form" text box field. It simply detaches from the top of the page (as it's fixed up there) and starts floating middle of the page when the virtual keyboard opens up.

Normal:

enter image description here

Broken:

enter image description here

like image 787
coldblooded01 Avatar asked Jan 24 '13 01:01

coldblooded01


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.

How do I change the position of the keyboard on my iPad?

Touch and hold the keyboard button in the lower-right corner of the keyboard. Slide your finger up to either Merge or Dock and Merge, then let go.

How do I lower keyboard on iPad?

How to make your iPad keyboard smaller. Open an app that uses the iPadOS keyboard — like Notes or Messages. Use two fingers to pinch the keyboard inward to make it smaller. Touch and hold the gray line to move the keyboard on your screen.


2 Answers

I really like this solution (http://dansajin.com/2012/12/07/fix-position-fixed/). I packaged it up into a little jQuery plugin so I could:

  • Set which parent gets the class
  • Set which elements this applies to (don't forget "textarea" and "select").
  • Set what the parent class name is
  • Allow it to be chained
  • Allow it to be used multiple times

Code example:

$.fn.mobileFix = function (options) {     var $parent = $(this),      $(document)     .on('focus', options.inputElements, function(e) {         $parent.addClass(options.addClass);     })     .on('blur', options.inputElements, function(e) {         $parent.removeClass(options.addClass);          // Fix for some scenarios where you need to start scrolling         setTimeout(function() {             $(document).scrollTop($(document).scrollTop())         }, 1);     });      return this; // Allowing chaining };  // Only on touch devices if (Modernizr.touch) {     $("body").mobileFix({ // Pass parent to apply to         inputElements: "input,textarea,select", // Pass activation child elements         addClass: "fixfixed" // Pass class name     }); } 

EDIT: Removed unnecessary element

like image 118
martinedwards Avatar answered Oct 02 '22 20:10

martinedwards


In our case this would fix itself as soon as user scrolls. So this is the fix we've been using to simulate a scroll:

$(document).on('blur', 'input, textarea', function () {     setTimeout(function () {         window.scrollTo(document.body.scrollLeft, document.body.scrollTop);     }, 0); }); 
like image 25
basarat Avatar answered Oct 02 '22 19:10

basarat