1

is there a possibility to get position of clicked event with eventClick method?

 var calendar = new Calendar(calendarEl, {

  eventClick: function(info) {
    alert('Event: ' + info.event.title);
    alert('Coordinates: ' + info.jsEvent.pageX + ',' + info.jsEvent.pageY);
    alert('View: ' + info.view.type);

    // change the border color just for fun
    info.el.style.borderColor = 'red';
  }

});

info.jsEvent.pageX is returning position of mouse.

Thank you guys for your help, i've decided to use modal for this.

thank you

John
  • 536
  • 6
  • 18
tomas
  • 121
  • 1
  • 2
  • 11
  • why do you want to know? If you want to know the start/end time of the event then just look at the properties of the fullCalendar event, rather than the JS event. – ADyson Mar 26 '19 at 16:07
  • i want to show div next to event element – tomas Mar 26 '19 at 17:24
  • You mean like a popover? Better to use a ready made library for that. Or, if you really want to do it yourself, use CSS to position it relative to the event element, much easier than trying to sort out coordinates – ADyson Mar 26 '19 at 17:28
  • after click on event I want to show div with option to delete or edit event – tomas Mar 26 '19 at 17:40
  • Yes you already said that. And I already suggested better ways to do it than using coordinates. What's your point? – ADyson Mar 26 '19 at 19:12

3 Answers3

0

sorry i did not realize you were using V4 at first.

you can get the calendar element with info.el
to get the offsets of the element you could use:
info.el.offsetLeft for the x and info.el.offsetTop for y coordinates (relative to the calendar)

John
  • 536
  • 6
  • 18
  • this is working, but left position is always 0. I think it takes position to – tomas Mar 26 '19 at 18:06
  • yes it's related to the parent element. if you want the exact position i think you have to get all the parent elements offsets too here's a link to a question where it's explained how to do that: https://stackoverflow.com/questions/442404/retrieve-the-position-x-y-of-an-html-element – John Mar 26 '19 at 19:22
0

According to John's answer :

const
   bodyRect = document.body.getBoundingClientRect(),
   elemRect = info.el.getBoundingClientRect(),
   offsetLeft   = elemRect.left - bodyRect.left,
   offsetTop   = elemRect.top - bodyRect.top
;

It works perfectly on V4.

Antoine Bourlart
  • 781
  • 2
  • 6
  • 12
0

alert('Coordinates: ' + info.jsEvent.screenX + ',' + info.jsEvent.screenY);

Harish
  • 1
  • 1
    As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Mar 30 '22 at 10:57
  • While this code may solve the question, [including an explanation](//meta.stackexchange.com/q/114762) of how and why this solves the problem would really help to improve the quality of your post, and probably result in more up-votes. Remember that you are answering the question for readers in the future, not just the person asking now. Please [edit] your answer to add explanations and give an indication of what limitations and assumptions apply. – Yunnosch Jun 21 '22 at 05:49