是否可以使用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正在返回鼠标位置。
谢谢你们的帮助,我决定为此使用模式。
谢谢
答案 0 :(得分:0)
对不起,我最初没有意识到您正在使用V4。
您可以使用info.el
获取日历元素
获取元素的偏移量,您可以使用:
info.el.offsetLeft
用于x坐标,info.el.offsetTop
用于y坐标(相对于日历)
答案 1 :(得分:0)
根据约翰的回答:
const
bodyRect = document.body.getBoundingClientRect(),
elemRect = info.el.getBoundingClientRect(),
offsetLeft = elemRect.left - bodyRect.left,
offsetTop = elemRect.top - bodyRect.top
;
它在V4上完美运行。