首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >完整日历:显示某一天的所有事件,当他在他的天单元格上徘徊时。

完整日历:显示某一天的所有事件,当他在他的天单元格上徘徊时。
EN

Stack Overflow用户
提问于 2017-11-08 11:52:10
回答 2查看 1.6K关注 0票数 1

我正在通过满历开发一个日历应用程序。

我目前正在做一个小型日历。迷你日历将不显示事件。

我试着用工具提示代替。因此,当用户在一个特定的daycell上鼠标操作时--特定的daycell的所有事件都将通过工具提示显示。(这是我的问题)

我已经在这个问题上工作了将近两天了。

不幸的是,完整的日历只提供"eventMouseover“。(没有dayMouseover )。

另外,使用$(“. really”).hover并不是最好的方法,因为它只有在单元格底部悬停时才能工作。

到目前为止,网络上还没有这方面的文档。

谁知道解决问题的最佳方法是什么?

到目前为止,我的代码如下:

代码语言:javascript
运行
复制
    $("#miniCalendar").fullCalendar({

        defaultDate: currentDate,
        viewRender: function (view, element)
        {
            monthStart = view.intervalStart.format("YYYY-MM-DD");
            monthEnd = view.intervalEnd.subtract(1, "days");
            monthEnd = view.intervalEnd.format("YYYY-MM-DD");
            mStart = view.intervalStart.format("M");
            yStart = view.intervalStart.format("YYYY");
        },
        events: function (start, end, timezone, callback) { //custom events function to be called every time the view changes

        $.ajax({
          url: getMonthDataUrl,
          type: "post",
          data: {
          startDate: monthStart,
          endDate: monthEnd,
           custom_config: Config
          },
          error: function () {
          //alert("there was an error while fetching events!");
          },
          success: function (data) {
          calendarData = data;
          console.log(calendarData);
          thingsToDoAfterWeLoadCalendarData(calendarData);
          callback(eventsJsonArray); //pass the event data to fullCalendar via the supplied callback function                                          
                     }
                  });

        },
        fixedWeekCount: false,
        dayRender:
          function (date, cell) {
          //the events are loaded vie eventAfterAllRender function
          //eventAfterAllRender takes time to load. so we need dayRender function in order to give the calendar default colors until the real colors are loaded
          // the default colors spouse to look like the correct colors. this is needed for a better looking calendar while loading new events
          if (!cell.hasClass("fc-other-month")) {
          //that means this is a cell of this current month (becuase only cells that belong to other month have the "fc-other-month" class
          var weekDay = date.format("dddd");
                  if (weekDay == "Saturday" || weekDay == "Friday") {
          cell.css("background-color", "#edf5f9");
          } else{
          //regular days
          cell.css("background-color", "#f7fafc");
          }
          } else{
          //cells that belong to the other months 
          $(".fc-other-month").css("background-color", "#ffffff");
          }

          },

          eventAfterAllRender: 
            (function(view, event, element) {
            let viewDisplay = $("#miniCalendar").fullCalendar("getView");
                    if (viewDisplay.name == "month") { //checking if this the month view. this is needed for better display of the week\day view (if we ever want to use it)
            $(".fc-day:not(.fc-other-month)").each(function(index, element) {
            //loop through each current month day cell
            $(this).empty(); //removing old icons in case they are displayed                                 
                    let cellDate = moment($(this).data("date")).format("YYYY-M-D"); // "YYYY-M-D" date format is the key in the json_backgrundColorBigCalendar array
                    $(this).css("background-color", json_backgrundColorBigCalendar[cellDate]); //set the background colour of the cell from the json_backgrundColorBigCalendar array.           
            });
        }

        $(".fc-other-month").css("background-color", "#ffffff"); //days that belong to other month gets a color background that will show this days are irrelevant

        }),
        dayClick: function(date, jsEvent, view) {
        window.location = fullCalendarUrl;
        },
});
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2017-11-08 12:19:25

我真的不知道是否有一个“完整的日历方式”这样做,但你为什么不能使用你的悬停事件侦听器,只是让它在fc-day-top悬停监听?

代码语言:javascript
运行
复制
$(".fc-day, .fc-day-top").hover(function(e) {
    console.log($(e.currentTarget).data("date")); 
});

如果您将日间单元格的顶部悬停,此操作也将有效。

更新:

要使事件处于悬停状态,请使用以下命令:

代码语言:javascript
运行
复制
var $calendar = $("#calendar");
$(".fc-day, .fc-day-top").hover(function(e) {
        var date = moment.utc($(e.currentTarget).data("date"));
        var events = $calendar.fullCalendar("clientEvents", function(event) { return event.start.startOf("day").isSame(date); });
        console.log(events);
    });    

(在完整日历主站点上的日历上测试)。

当然,您必须更改日历的jQuery选择器(#calendar),因为它在您的代码中。

票数 2
EN

Stack Overflow用户

发布于 2017-11-08 12:28:47

我以前从未见过完整的日历,但是如果我理解正确的话,您希望将一个悬停函数绑定到日历的自定义日期。对吗?

如果是这样的话,您可以简单地选择日历上带有“数据日期”属性的天数。因此,下面的代码将允许您为所需的一天指定一个悬停函数:

代码语言:javascript
运行
复制
$("[data-date='2017-10-10']").hover(function(e) {
    console.log("You moused over 10/10/2017!"); 
}); 
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47179014

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档