【问题标题】:React Fullcallendar v5 event positioning toward cursor issue [UPDATED]React Fullcallendar v5 事件定位到光标问题 [更新]
【发布时间】:2020-11-20 16:18:30
【问题描述】:

我正在尝试创建一个包含 Fullcalendar 的反应应用程序。

我已经设法让它工作了,但是当我在其中拖动事件时遇到了一个奇怪的问题。An event element jumps somewhere and then follows my cursor at distance.

当我释放鼠标按钮时,事件元素会跳转到日历上突出显示的日期。我尝试将相对定位添加到不同的父元素以在它们内部进行事件定位,但没有成功。

这是我的代码

import FullCalendar from '@fullcalendar/react'
import dayGridPlugin from '@fullcalendar/daygrid';
import timeGridPlugin from "@fullcalendar/timegrid";
import interactionPlugin, { Draggable } from '@fullcalendar/interaction';
import Alert from "sweetalert2";

const Dashboard = () => {

    useEffect(() => {
        let draggableEl = document.getElementById("external-events");
        new Draggable(draggableEl, {
            itemSelector: ".fc-event",
            eventData: function(eventEl) {
                let title = eventEl.getAttribute("title");
                let id = eventEl.getAttribute("data");
                return {
                    title: title,
                    id: id
                };
            }
        });
    }, []);

    const state = {
        calendarEvents: [
            {
                title: "Birthday Party",
                start: new Date("2020-11-17 00:00"),
                id: "99999998"
            },
            {
                title: "Repeating Event",
                start: new Date("2020-11-05 00:00"),
                id: "99999999"
            },
            {
                title: "Repeating Event",
                start: new Date("2020-11-12 00:00"),
                id: "99999999"
            },
            {
                title: "Repeating Event",
                start: new Date("2020-11-22 00:00"),
                id: "99999999"
            },
        ]
    };


    const eventClick = (eventClick) => {
        Alert.fire({
            title: eventClick.event.title,
            html:
                `<div class="table-responsive">
      <table class="table">
      <tbody>
      <tr >
      <td>Title</td>
      <td><strong>` +
                eventClick.event.title +
                `</strong></td>
      </tr>
      <tr >
      <td>Start Time</td>
      <td><strong>
      ` +
                eventClick.event.start +
                `
      </strong></td>
      </tr>
      </tbody>
      </table>
      </div>`,

            showCancelButton: true,
            confirmButtonColor: "#d33",
            cancelButtonColor: "#3085d6",
            confirmButtonText: "Remove Event",
            cancelButtonText: "Close"
        }).then(result => {
            if (result.value) {
                eventClick.event.remove(); // It will remove event from the calendar
                Alert.fire("Deleted!", "Your Event has been deleted.", "success");
            }
        });
    };

return (
                                    <FullCalendar
                                        headerToolbar={{
                                            left: 'prev,next today',
                                            center: 'title',
                                            right: 'dayGridMonth,timeGridWeek,timeGridDay'
                                        }}
                                        rerenderDelay={10}
                                        eventDurationEditable={false}
                                        editable={true}
                                        droppable={true}
                                        plugins={[dayGridPlugin, timeGridPlugin, interactionPlugin]}
                                        events={state.calendarEvents}
                                        drop={drop}
                                        eventClick={eventClick}
                                        selectable={false}
                                    />
)
};
export default Dashboard;

我做错了什么?

更新: 我发现了发生了什么,但我仍然不知道该怎么办。

我的项目中有一个左侧边栏和标题,如果没有这些元素,FullCalendar 可以正常工作。此外,它在 timeGridDay 视图和 timeGridWeek 上也能正常工作。

所以基本上它只在 dayGridMonth 视图上不能正常工作。似乎在 dayGridMonth 视图中它没有正确计算位置。

这里可以做什么?

【问题讨论】:

  • 代码没有显示任何明显的问题。也许是CSS问题?除了 fullCalendar CSS 之外,页面中还有其他 CSS 吗?
  • @ADyson,抱歉回复晚了,但我又遇到了这个错误。当然,我在页面上还有其他 CSS。但我不确定如何调试它,因为 timeGridDay 视图和 timeGridWeek 没有发生问题
  • 感谢您的建议@ADyson!这是导致问题的第三方 css
  • 没问题。顺便说一句,您不需要将标题更改为已解决。有一个公认的答案的事实已经表明:-)

标签: html css reactjs fullcalendar fullcalendar-5


【解决方案1】:

解决了。问题出在我正在使用的 animated.css 中。删除后一切正常。

【讨论】:

  • 或许您可以告诉我们第 3 方组件是什么,以防有人在搜索类似的东西?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-04-17
  • 1970-01-01
  • 1970-01-01
  • 2022-06-17
  • 1970-01-01
  • 2012-03-23
  • 1970-01-01
相关资源
最近更新 更多