Modernizr 很棒,但示例测试position: fixed
非常不完整:
- iOS 4 及更低版本的退货
true
,但不支持position: fixed
- Windows 上的 Opera 在支持时
false
返回position: fixed
我发现了另一个基于 Modernizr 测试但添加了 iOS 检测的测试:https ://gist.github.com/855078/109ded4b4dab65048a1e7b4f4bd94c93cebb26b8 。由于即将推出的 iOS 5 确实支持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;
});