Select2 produces rough scrolling on mobile

与世无争的帅哥 提交于 2019-12-07 11:35:29

Reading your answer, it is not very clear how to add the -webkit-overflow-scrolling: touch; property to the select2 element, so I've decided to give a more detailed answer:

Details:

According to specs (https://developer.mozilla.org/en-US/docs/Web/CSS/-webkit-overflow-scrolling), the -webkit-overflow-scrolling CSS property controls whether or not touch devices use momentum-based scrolling for a given element.

A touch value means that the content continues to scroll for a while after finishing the scroll gesture and removing your finger from the touchscreen.

However, this property applies only for iOS devices. Android works well even without it.

Usage:

We must append this property to the dropdown element that holds the suggestions - .select2-results__options.

Add the following code after the select2 css styles:

.select2-results__options {
    -webkit-overflow-scrolling: touch;
}

Demo:

https://codepen.io/andreivictor/pen/NYvvXP

(the following demo contains two select2 instances for a better comparison of the scroll effects)

Tested on:

  • iPhone 6 Plus (iOS 10.3.2)
  • iPhone 8 (iOS 11.2.5)
  • iPad Mini 3 (iOS 10.3.2)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!