test for overflow-y:auto returning true on android < 3 even though it doesnt work

守給你的承諾、 提交于 2019-12-06 10:35:16

You can try this:

Modernizr.addTest("overflowscrolling",function(){
    return Modernizr.testAllProps("overflowScrolling");
});

Then check for the overflowscrolling or no-overflowscrolling class that Modernizr will insert into the html element in the DOM. This seems to work correctly for iOS and Android devices. (Or just check the value of Modernizr.overflowscrolling directly.)

Because overflowscrolling is specific to certain browsers/devices (e.g., recent iPhones), I check for Modernizr.touch as well. If it's not a touch device, I assume it can handle overflow scrolling. Since Androids are touch devices, they will be tested with Modernizr.overflowscrolling but you don't have to test, say, Chrome on a laptop (which will return false but can handle overflow:auto just fine).

So the test may be imperfect, but it seems to do the right thing for all the use cases I care about that I've tested: All modern desktop browsers, recent iPhones, and Android 2.X devices. If you have a wider array of devices/browsers to support, you'll have to test those and tweak as appropriate.

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