tool-shack 0.0.18 → 0.0.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getElementOffset } from '../dom/getElementOffset.js';
|
|
2
2
|
import { scrollToPosition } from './scrollToPosition.js';
|
|
3
3
|
/**
|
|
4
4
|
* Scroll window to make HTMLElement visible
|
|
@@ -10,6 +10,6 @@ import { scrollToPosition } from './scrollToPosition.js';
|
|
|
10
10
|
*/
|
|
11
11
|
export const scrollToElement = (element, offset = 0, smoothScroll = true) => {
|
|
12
12
|
offset = offset ?? window.innerHeight / 6;
|
|
13
|
-
scrollToPosition(0,
|
|
13
|
+
scrollToPosition(0, getElementOffset(element).top - offset, smoothScroll);
|
|
14
14
|
};
|
|
15
15
|
//# sourceMappingURL=scrollToElement.js.map
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* @param element HTMLElement for which should be calculated offset
|
|
5
5
|
* @returns Object with top and left offset value
|
|
6
6
|
*/
|
|
7
|
-
export declare const
|
|
7
|
+
export declare const getElementOffset: (element: HTMLElement) => {
|
|
8
8
|
top: number;
|
|
9
9
|
left: number;
|
|
10
10
|
};
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* @param element HTMLElement for which should be calculated offset
|
|
5
5
|
* @returns Object with top and left offset value
|
|
6
6
|
*/
|
|
7
|
-
export const
|
|
7
|
+
export const getElementOffset = (element) => {
|
|
8
8
|
const box = element.getBoundingClientRect();
|
|
9
9
|
return { top: box.top + window.pageYOffset, left: box.left + window.pageXOffset };
|
|
10
10
|
};
|
package/package.json
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getElementOffset } from '../dom/getElementOffset.js';
|
|
2
2
|
import { scrollToPosition } from './scrollToPosition.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -16,5 +16,5 @@ export const scrollToElement = (
|
|
|
16
16
|
): void => {
|
|
17
17
|
offset = offset ?? window.innerHeight / 6;
|
|
18
18
|
|
|
19
|
-
scrollToPosition(0,
|
|
19
|
+
scrollToPosition(0, getElementOffset(element).top - offset, smoothScroll);
|
|
20
20
|
};
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* @param element HTMLElement for which should be calculated offset
|
|
5
5
|
* @returns Object with top and left offset value
|
|
6
6
|
*/
|
|
7
|
-
export const
|
|
7
|
+
export const getElementOffset = (element: HTMLElement): { top: number; left: number } => {
|
|
8
8
|
const box: DOMRect = element.getBoundingClientRect();
|
|
9
9
|
|
|
10
10
|
return { top: box.top + window.pageYOffset, left: box.left + window.pageXOffset };
|