You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

30 lines
881 B

2 months ago
  1. import getWindow from "./getWindow.js";
  2. import getDocumentElement from "./getDocumentElement.js";
  3. import getWindowScrollBarX from "./getWindowScrollBarX.js";
  4. import isLayoutViewport from "./isLayoutViewport.js";
  5. export default function getViewportRect(element, strategy) {
  6. var win = getWindow(element);
  7. var html = getDocumentElement(element);
  8. var visualViewport = win.visualViewport;
  9. var width = html.clientWidth;
  10. var height = html.clientHeight;
  11. var x = 0;
  12. var y = 0;
  13. if (visualViewport) {
  14. width = visualViewport.width;
  15. height = visualViewport.height;
  16. var layoutViewport = isLayoutViewport();
  17. if (layoutViewport || !layoutViewport && strategy === 'fixed') {
  18. x = visualViewport.offsetLeft;
  19. y = visualViewport.offsetTop;
  20. }
  21. }
  22. return {
  23. width: width,
  24. height: height,
  25. x: x + getWindowScrollBarX(element),
  26. y: y
  27. };
  28. }