Modernizr位置固定测试不完整
Modernizr position fixed test incomplete
Modernizr很棒,但position: fixed
的示例测试非常不完整:
- iOS 4及更低版本在不支持
position: fixed
的情况下返回true
- Windows上的Opera返回
false
,但它确实支持position: fixed
我发现了另一个基于Modernizr测试的测试,但添加了iOS检测:https://gist.github.com/855078/109ded4b4dab65048a1e7b4f4bd94c93cebb26b8.由于即将推出的iOS5确实支持position: fixed
,因此它并不能真正经得起未来的考验。
你们能帮我找到一种不用浏览器嗅探就能在iOS中测试固定位置的方法吗?
// Test for position:fixed support
Modernizr.addTest('positionfixed', function () {
var test = document.createElement('div'),
control = test.cloneNode(false),
fake = false,
root = document.body || (function () {
fake = true;
return document.documentElement.appendChild(document.createElement('body'));
}());
var oldCssText = root.style.cssText;
root.style.cssText = 'padding:0;margin:0';
test.style.cssText = 'position:fixed;top:42px';
root.appendChild(test);
root.appendChild(control);
var ret = test.offsetTop !== control.offsetTop;
root.removeChild(test);
root.removeChild(control);
root.style.cssText = oldCssText;
if (fake) {
document.documentElement.removeChild(root);
}
return ret;
});
我为iOS编写了这个测试:http://mnobeta.no/2011/09/test-position-fixed-for-iphone/
它有点乱,但似乎能用。安卓仍然是一个问题,因为它的"假"position:fixed
。
我发现你需要插入一些技巧来获得功能定位固定测试。例如,我在测试中插入了一个破解,该破解对于运行v.5或更高版本的iOS设备返回true:
/*iPhone/iPad Hack*/
if(navigator.userAgent.match(/iPad|iPhone/i) !== null){
/*Check if device runs iOS 5 or higher*/
isSupported = navigator.userAgent.match(/[5-9]_[0-9]/) !== null;
}
我不确定这个代码有多"干净",但它对我来说很有用。
相关文章:
- 模糊事件的Javascript测试
- 我的单元测试选项是什么
- jquery试图按名称获取按钮位置
- 我可以获得相对于被点击元素的确切点击位置吗
- 谷歌地图固定位置覆盖
- 在单击任何位置时隐藏元素,而不检查每次DOM单击
- 测试索引值是否等于某个数字的倍数
- 在localhost Dev Box上测试JSONP请求的最佳方式
- 循环比赛位置算法
- 测试iFrame的位置.href是在jasmine单元测试中设置的
- 是否可以模拟 qUnit 测试的窗口位置对象
- 单元测试窗口位置分配的角度问题
- 开玩笑:测试数组的随机位置
- 测试是否已授予 html5 地理位置权限
- 使用 JsTestDriver 进行地理位置单元测试
- 传递一个位置.搜索参数到Jasmine (Karma)测试
- 量角器测试-如何将鼠标位置重置为默认原点
- 如何测试水平鼠标位置是否等于Javascript中的一个变量
- AngularJs测试.模板放置位置
- Modernizr位置固定测试不完整