测试溢出-Y:自动返回在Android&LT真实的; 3,即使它不工作 [英] test for overflow-y:auto returning true on android < 3 even though it doesnt work

查看:175
本文介绍了测试溢出-Y:自动返回在Android&LT真实的; 3,即使它不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

IM开发Android web应用程序。在一个地方,我需要找到是否溢出-Y:汽车支持与否在浏览器,因为我需要滚动的div。结果
但对于这个回报在 Android和LT真正的测试; 3 ,告诉它的支持,但使用时,它不工作的方式其预期,即用DIV

im developing a webapp for android. At a place i need to find whether overflow-y:auto is supported or not in the browser because i need to scroll a div.
But tests for this return true in android < 3, telling that its supported, but when used it doesnt work the way its expected, i.e., the div with

overflow-y:auto 

犯规滚动。

有没有,看看这个属性是在浏览器中支持任何可信的方式。我使用Modernizr的写了这个测试,但它总是返回true,这意味着它的支持。

Is there any credible way to see if this property is supported in a browser. i wrote this test using modernizr, but it always returns true, meaning that its supported.

Modernizr.addTest('overflowauto', function(){
var bool = false;
var testProp = "overflow-y";
var testVal = "auto";
var styles = Modernizr._prefixes.join(testProp + ":" + testVal + "; ");
var ret = true;
ret =  Modernizr.testStyles('#modernizr { '+styles+' }', function(elem, rule){
    for(var i = 0; i < Modernizr._prefixes.length; i++) {
        bool = (window.getComputedStyle ?
                getComputedStyle(elem, null) :
                elem.currentStyle)[Modernizr._prefixes[i] + testProp] == testVal;

        if(bool) break;
    }

    return bool;

});
return ret;

});

但是,当我用它显然它不工作。
请告诉我的以可信的方式找到,如果财产安全使用,或者我可以做些什么。

But clearly its not working when i use it. Please tell me a credible way to find if the property is safe to use, or what can i do about it.

推荐答案

您可以试试这个:

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

然后检查 overflowscrolling 的Modernizr的将插入类> HTML 中的DOM元素。这似乎为iOS和Android设备的正常工作。 (或者只是检查的值 Modernizr.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.)

由于 overflowscrolling 是特定于某些浏览器/设备(如iPhone手机近期的),我检查 Modernizr.touch 为好。如果它不是一个触摸设备,我相信它可以处理溢出滚动。由于机器人是触摸屏设备,他们将与 Modernizr.overflowscrolling 进行测试,但你没有来测试,比如说Chrome的一台笔记本电脑(这将返回false,但可以处理溢出:汽车就好了)

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).

因此​​,测试可能是不完美的,但它似乎做正确的事情对所有使用情况下,我在乎的是我测试过的:所有的现代桌面浏览器,iPhone手机近期和Android 2.X设备。如果你的设备/浏览器更广泛的阵列支持,你必须测试这些并酌情调整。

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.

这篇关于测试溢出-Y:自动返回在Android&LT真实的; 3,即使它不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆