main
Last change
on this file was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 2 weeks ago |
F4 Finalna Verzija
|
-
Property mode
set to
100644
|
File size:
1.3 KB
|
Line | |
---|
1 | import { isElement, isHTMLElement } from "./instanceOf.js";
|
---|
2 | import { round } from "../utils/math.js";
|
---|
3 | import getWindow from "./getWindow.js";
|
---|
4 | import isLayoutViewport from "./isLayoutViewport.js";
|
---|
5 | export default function getBoundingClientRect(element, includeScale, isFixedStrategy) {
|
---|
6 | if (includeScale === void 0) {
|
---|
7 | includeScale = false;
|
---|
8 | }
|
---|
9 |
|
---|
10 | if (isFixedStrategy === void 0) {
|
---|
11 | isFixedStrategy = false;
|
---|
12 | }
|
---|
13 |
|
---|
14 | var clientRect = element.getBoundingClientRect();
|
---|
15 | var scaleX = 1;
|
---|
16 | var scaleY = 1;
|
---|
17 |
|
---|
18 | if (includeScale && isHTMLElement(element)) {
|
---|
19 | scaleX = element.offsetWidth > 0 ? round(clientRect.width) / element.offsetWidth || 1 : 1;
|
---|
20 | scaleY = element.offsetHeight > 0 ? round(clientRect.height) / element.offsetHeight || 1 : 1;
|
---|
21 | }
|
---|
22 |
|
---|
23 | var _ref = isElement(element) ? getWindow(element) : window,
|
---|
24 | visualViewport = _ref.visualViewport;
|
---|
25 |
|
---|
26 | var addVisualOffsets = !isLayoutViewport() && isFixedStrategy;
|
---|
27 | var x = (clientRect.left + (addVisualOffsets && visualViewport ? visualViewport.offsetLeft : 0)) / scaleX;
|
---|
28 | var y = (clientRect.top + (addVisualOffsets && visualViewport ? visualViewport.offsetTop : 0)) / scaleY;
|
---|
29 | var width = clientRect.width / scaleX;
|
---|
30 | var height = clientRect.height / scaleY;
|
---|
31 | return {
|
---|
32 | width: width,
|
---|
33 | height: height,
|
---|
34 | top: y,
|
---|
35 | right: x + width,
|
---|
36 | bottom: y + height,
|
---|
37 | left: x,
|
---|
38 | x: x,
|
---|
39 | y: y
|
---|
40 | };
|
---|
41 | } |
---|
Note:
See
TracBrowser
for help on using the repository browser.