Fullcalendar - 如何获得点击事件的位置
Fullcalendar - how to get position of clicked event
是否有可能通过 eventClick 方法获取点击事件的位置?
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 正在返回鼠标位置。
谢谢大家的帮助,我决定为此使用模态。
谢谢
抱歉,我一开始没有意识到您使用的是 V4。
您可以通过 info.el
获取日历元素
获取您可以使用的元素的偏移量:
info.el.offsetLeft
x 和 info.el.offsetTop
y 坐标(相对于日历)
根据约翰的回答:
const
bodyRect = document.body.getBoundingClientRect(),
elemRect = info.el.getBoundingClientRect(),
offsetLeft = elemRect.left - bodyRect.left,
offsetTop = elemRect.top - bodyRect.top
;
它在 V4 上完美运行。
警报('Coordinates: ' + info.jsEvent.screenX + ',' + info.jsEvent.screenY);
是否有可能通过 eventClick 方法获取点击事件的位置?
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 正在返回鼠标位置。
谢谢大家的帮助,我决定为此使用模态。
谢谢
抱歉,我一开始没有意识到您使用的是 V4。
您可以通过 info.el
获取日历元素
获取您可以使用的元素的偏移量:
info.el.offsetLeft
x 和 info.el.offsetTop
y 坐标(相对于日历)
根据约翰的回答:
const
bodyRect = document.body.getBoundingClientRect(),
elemRect = info.el.getBoundingClientRect(),
offsetLeft = elemRect.left - bodyRect.left,
offsetTop = elemRect.top - bodyRect.top
;
它在 V4 上完美运行。
警报('Coordinates: ' + info.jsEvent.screenX + ',' + info.jsEvent.screenY);