Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mobile Safari - Input caret does not scroll along with overflow-scrolling: touch

I know that Mobile Safari won't fire events while in "momentum" (-webkit-overflow-scrolling: touch;) scrolling. But this is not entirely the same thing, because Safari handles the (blinking) caret of an input internally.

<div id="container">
    <input type="text" />
    <div class="filling"></div>
</div>

#container {
    position: absolute;
    top: 20px;
    bottom: 20px;
    width: 50%;
    -webkit-overflow-scrolling: touch;
    overflow-y: auto;
    border: 1px solid black;
}

input {
    margin-top: 60vh;
}

.filling {
    height: 200vh;
}

Try this fiddle on your device (focus the input and then scroll): https://jsfiddle.net/gabrielmaldi/n5pgedzv

The issue also happens when you keep your finger pressed (i.e. not only when giving it momentum and releasing): the caret fails to scroll.

Obviously I don't want to turn off overflow scrolling, if there's no way to fix the caret so it will scroll correctly, it would be OK to hide it.

Thanks

like image 583
gabrielmaldi Avatar asked Dec 23 '13 05:12

gabrielmaldi


People also ask

What is momentum scrolling?

Use momentum-based scrolling, where the content continues to scroll for a while after finishing the scroll gesture and removing your finger from the touchscreen. The speed and duration of the continued scrolling is proportional to how vigorous the scroll gesture was. Also creates a new stacking context.

Can I use webkit overflow scrolling?

This means that you cannot use webkit-overflow-scrolling:touch in PhoneGap apps, and for most other use cases at this time. Instead you can use overflow: scroll, but that's only supported in Android 3.0+, so use iScroll, or the many other alternatives out there.


2 Answers

This is indeed a WebKit bug and there seems to be no known workaround.

@cvrebert filed the bug:

  • WebKit: https://bugs.webkit.org/show_bug.cgi?id=138201
  • Apple Radar: http://openradar.appspot.com/18819624
like image 199
gabrielmaldi Avatar answered Oct 22 '22 15:10

gabrielmaldi


Had this same problem, my fix was altering between

-webkit-overflow-scrolling: touch

and

-webkit-overflow-scrolling: auto

whenever i focus/blur on inputs

like image 21
Shakks Avatar answered Oct 22 '22 14:10

Shakks