mirror of
https://github.com/pandorafms/pandorafms.git
synced 2025-07-31 01:35:36 +02:00
Improved a lib function
This commit is contained in:
parent
394815daa6
commit
f6dfe023e9
@ -405,10 +405,15 @@ export function debounce<T>(delay: number, fn: (...args: T[]) => void) {
|
|||||||
* Retrieve the offset of an element relative to the page.
|
* Retrieve the offset of an element relative to the page.
|
||||||
* @param el Node used to calculate the offset.
|
* @param el Node used to calculate the offset.
|
||||||
*/
|
*/
|
||||||
function getOffset(el: HTMLElement | null) {
|
function getOffset(el: HTMLElement | null, parent?: HTMLElement) {
|
||||||
let x = 0;
|
let x = 0;
|
||||||
let y = 0;
|
let y = 0;
|
||||||
while (el && !Number.isNaN(el.offsetLeft) && !Number.isNaN(el.offsetTop)) {
|
while (
|
||||||
|
el &&
|
||||||
|
!Number.isNaN(el.offsetLeft) &&
|
||||||
|
!Number.isNaN(el.offsetTop) &&
|
||||||
|
el !== parent
|
||||||
|
) {
|
||||||
x += el.offsetLeft - el.scrollLeft;
|
x += el.offsetLeft - el.scrollLeft;
|
||||||
y += el.offsetTop - el.scrollTop;
|
y += el.offsetTop - el.scrollTop;
|
||||||
el = el.offsetParent as HTMLElement | null;
|
el = el.offsetParent as HTMLElement | null;
|
||||||
@ -548,8 +553,10 @@ export function addMovementListener(
|
|||||||
|
|
||||||
// Store the difference between the cursor and
|
// Store the difference between the cursor and
|
||||||
// the initial coordinates of the element.
|
// the initial coordinates of the element.
|
||||||
lastX = element.offsetLeft;
|
const elementOffset = getOffset(element, container);
|
||||||
lastY = element.offsetTop;
|
lastX = elementOffset.left;
|
||||||
|
lastY = elementOffset.top;
|
||||||
|
|
||||||
// Store the mouse position.
|
// Store the mouse position.
|
||||||
lastMouseX = e.pageX;
|
lastMouseX = e.pageX;
|
||||||
lastMouseY = e.pageY;
|
lastMouseY = e.pageY;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user