scrollparent.js 874 B

12345678910111213141516171819202122232425262728293031323334
  1. (function (root, factory) {
  2. if (typeof define === "function" && define.amd) {
  3. define([], factory);
  4. } else if (typeof module === "object" && module.exports) {
  5. module.exports = factory();
  6. } else {
  7. root.Scrollparent = factory();
  8. }
  9. }(this, function () {
  10. function isScrolling(node) {
  11. var overflow = getComputedStyle(node, null).getPropertyValue("overflow");
  12. return overflow.indexOf("scroll") > -1 || overflow.indexOf("auto") > - 1;
  13. }
  14. function scrollParent(node) {
  15. if (!(node instanceof HTMLElement || node instanceof SVGElement)) {
  16. return undefined;
  17. }
  18. var current = node.parentNode;
  19. while (current.parentNode) {
  20. if (isScrolling(current)) {
  21. return current;
  22. }
  23. current = current.parentNode;
  24. }
  25. return document.scrollingElement || document.documentElement;
  26. }
  27. return scrollParent;
  28. }));