Skip to content

Commit

Permalink
Update getCoords function
Browse files Browse the repository at this point in the history
  • Loading branch information
themitosan committed Aug 20, 2023
1 parent 89a3146 commit 65c4ecd
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/TMS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -315,25 +315,28 @@ export function getRect(elementId:string){
/**
* Get element coords based on parent element
* @param elementId DOM ID target
* @returns T: Y, L: X, W: Width, H: Height, WL: X Pos. + It's own width, TH: Y Pos. + It's own height
* @returns Object - T: Y, L: X, W: Width, H: Height, WL: X Pos. + It's own width, TH: Y Pos. + It's own height
*/
export function getCoords(elementId:string){

var res,
// Variables
var res:any = {},
elId = getElement(elementId);

// Check if element exists
if (elId !== null){

var top = elId.offsetTop,
left = elId.offsetLeft,
width = elId.getBoundingClientRect().width,
height = elId.getBoundingClientRect().height;

// Set res data
res = {
T: top,
L: left,
W: width,
H: height,
T: Number(top),
L: Number(left),
W: Number(width),
H: Number(height),
WL: parseFloat(width + left),
TH: parseFloat(top + height)
}
Expand All @@ -342,6 +345,7 @@ export function getCoords(elementId:string){
tmsWarn(`Unable to get coords because DOM does not exist! (${elementId})`);
}

// Return data
return res;

}
Expand Down

0 comments on commit 65c4ecd

Please sign in to comment.