Skip to content

Instantly share code, notes, and snippets.

@typeoneerror
Created December 9, 2011 15:36
Show Gist options
  • Select an option

  • Save typeoneerror/1452015 to your computer and use it in GitHub Desktop.

Select an option

Save typeoneerror/1452015 to your computer and use it in GitHub Desktop.
// test for fixed positioning
Modernizr.addTest("positionfixed", function()
{
// OK since iOS 5
//if (navigator.userAgent.match(/AppleWebKit\/(.*)Mobile\//)) return false;
if (navigator.userAgent.match(/Android(.*)Mobile/)) return false;
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;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment