Modernizr is great but the example test for position: fixed
is quite incomplete:
true
while it doesn't support position: fixed
false
while it does support position: fixed
I found another test based on the Modernizr test but with iOS detection added: https://gist.github.com/855078/109ded4b4dab65048a1e7b4f4bd94c93cebb26b8.
It isn't really future proof since the upcoming iOS 5 does support position: fixed
.
Can you guys help me find a way to test position fixed in iOS without browser sniffing?
// 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;
});
I wrote this test for iOS: http://mnobeta.no/2011/09/test-position-fixed-for-iphone/
It is a bit messy, but seems to work. Android is still a problem because of its "fake" position:fixed
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With