0

I have a straight forward draggable modal window via jquery kendu-ui.

My goal is to simply get the screen coordinates of the top left position of a modal, relative to the browser window... I am trying offset and getBoundingClientRect() methods, below is just an example of a few attempts, all attempts are constantly console logging 0, 0, .. what am I doing wrong here?

 let ktop = $(".k-window").offset().top;
 let ktlft = $(".k-window").offset().left;
 console.log(ktop + " " + ktlft);

 let ktl = document.querySelector('.k-window');
 let procoords = ktl.getBoundingClientRect();

 let ktl = document.querySelector('.k-window');
 let ktlTop = ktl.offsetTop;
 let ktlLeft = ktl.offsetLeft;
Dr Upvote
  • 8,023
  • 24
  • 91
  • 204
  • Is the `.k-window` element visible in the DOM when you try and read the values? – Rory McCrossan Apr 20 '20 at 08:57
  • absolutely, I am testing in the browser as it is already even up... and I still cannot console any coordinates – Dr Upvote Apr 20 '20 at 08:58
  • Is it possible for you to show a working example in the question? One thing to note is that if there are multiple `.k-window` elements in the DOM then all three of your code examples will only ever look at the first one. – Rory McCrossan Apr 20 '20 at 09:00

1 Answers1

0

Kendo by default creates two .k-window elements, one is for draggable purpose, the other is for "physical" window. Your attempts always take the first one that is stack to the top 0 and left 0 with visibility: visible, but with display: none.

One of the options is to find k-window wrapper by your window id:

$('#my-window').closest('.k-window');

Example: Get offset

dev_in_progress
  • 2,484
  • 2
  • 21
  • 32