Created
March 28, 2016 18:52
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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