Skip to content

Instantly share code, notes, and snippets.

@farinspace
Created September 29, 2014 22:46
Show Gist options
  • Save farinspace/40b4fd6e724e2d75b4d3 to your computer and use it in GitHub Desktop.
Save farinspace/40b4fd6e724e2d75b4d3 to your computer and use it in GitHub Desktop.
Javascript function to check if an element and/or its parents position is set to fixed
isPositionFixed = function (selector, traverseAncestors) {
var el = $(selector);
if (el.length) {
if (!traverseAncestors) {
return 'fixed' === el.css('position') ? true : false ;
}
var isFixed = false;
var els = el.add(el.parents());
els.each(function() {
if ('fixed' === $(this).css('position')) {
isFixed = true;
return false;
}
});
return isFixed;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment