scroll-parent.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /*!
  2. * jQuery UI Scroll Parent 1.14.1
  3. * https://jqueryui.com
  4. *
  5. * Copyright OpenJS Foundation and other contributors
  6. * Released under the MIT license.
  7. * https://jquery.org/license
  8. */
  9. //>>label: scrollParent
  10. //>>group: Core
  11. //>>description: Get the closest ancestor element that is scrollable.
  12. //>>docs: https://api.jqueryui.com/scrollParent/
  13. ( function( factory ) {
  14. "use strict";
  15. if ( typeof define === "function" && define.amd ) {
  16. // AMD. Register as an anonymous module.
  17. define( [ "jquery", "./version" ], factory );
  18. } else {
  19. // Browser globals
  20. factory( jQuery );
  21. }
  22. } )( function( $ ) {
  23. "use strict";
  24. return $.fn.scrollParent = function( includeHidden ) {
  25. var position = this.css( "position" ),
  26. excludeStaticParent = position === "absolute",
  27. overflowRegex = includeHidden ? /(auto|scroll|hidden)/ : /(auto|scroll)/,
  28. scrollParent = this.parents().filter( function() {
  29. var parent = $( this );
  30. if ( excludeStaticParent && parent.css( "position" ) === "static" ) {
  31. return false;
  32. }
  33. return overflowRegex.test( parent.css( "overflow" ) + parent.css( "overflow-y" ) +
  34. parent.css( "overflow-x" ) );
  35. } ).eq( 0 );
  36. return position === "fixed" || !scrollParent.length ?
  37. $( this[ 0 ].ownerDocument || document ) :
  38. scrollParent;
  39. };
  40. } );