jquery-modal icon indicating copy to clipboard operation
jquery-modal copied to clipboard

iOS scrolling when switching input fiels in a modal

Open stickbyatlas opened this issue 9 years ago • 3 comments

Hey folks,

Thanks for the solid modal plugin. Just sharing a solution to an issue I had when working with text input fields in a modal form. This only came up on iOS (e.g. iPad) when the modal was active and the height of the page was greater than the viewport. When switching between input fields (either using the 'next' button or tapping on one directly), the entire modal would jump to the top of the screen and scroll back down into view each time input focus changed. It was super janky and disorienting. To solve the problem, I added the following code in my CSS declarations. Just posting this here in case someone else experiences the same problem and searches the issue tracker. Cheers.

html,body{
    -webkit-overflow-scrolling : touch !important;
    overflow: auto !important;
    height: 100% !important;
}

stickbyatlas avatar Oct 05 '16 14:10 stickbyatlas

Hmm, thanks for the solution. but it seems to make the page unable to be scroll. Is there any other solution around this?

whitewolf92 avatar Oct 16 '16 05:10 whitewolf92

#180 is similar in fact that scrolling is handled. I would guess, that applying overflow: hidden on the html and body, when an modal is open, will not only resolve the scrolling issue mentioned in the related issue but it should also fix the problem you had.

Reason why this happens is, that the mobile devices try to scroll the form element into the viewport of the user. If scrolling is already hard/non-optimal under normal circumstances it may also happen when automatic tasks try to scroll the viewport.

Blackskyliner avatar Aug 09 '17 09:08 Blackskyliner

Also make sure, that your font-size is bigger than 16px on your input elements, otherwise mobile Safari will Zoom in to the Element causing the jankyness.

References:

  • https://stackoverflow.com/questions/2989263/disable-auto-zoom-in-input-text-tag-safari-on-iphone

Blackskyliner avatar Aug 25 '17 13:08 Blackskyliner