Skip to content

Instantly share code, notes, and snippets.

@nborko
Created March 28, 2016 18:52
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nborko/1c5ce81faac5dd8a1c7c to your computer and use it in GitHub Desktop.
Save nborko/1c5ce81faac5dd8a1c7c to your computer and use it in GitHub Desktop.
Like jquery-ui scrollParent function except it works on jQuery objects containing multiple elements
/* like jquery-ui scrollParent function except it works on jQuery objects containing multiple elements */
(function ($) {
$.fn.scrollParent = (function (overflowRegex) {
return function () {
return $($.unique(this.map(function () {
var position = $(this).css('position'),
excludeStaticParent = position === 'absolute',
scrollParent = $(this).parents().filter(function() {
var parent = $(this);
if (excludeStaticParent && parent.css('position') === 'static') {
return false;
}
return (overflowRegex).test(parent.css('overflow') + parent.css('overflow-y') + parent.css('overflow-x'));
}).eq(0);
return position === 'fixed' || !scrollParent.length ? $(this.ownerDocument || document) : scrollParent.get();
}).get()));
};
})(/(auto|scroll)/);
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment