【问题标题】:Jquery Full calendar and dynamic event colorsJquery 完整的日历和动态事件颜色
【发布时间】:2011-01-27 08:30:52
【问题描述】:

我想通过我的 json 事件源为 jquery fullcalendar 传递事件的颜色,我该如何实现?

【问题讨论】:

    标签: jquery fullcalendar


    【解决方案1】:

    没有比这更容易的了。如果您查看 jQuery Fullcalendar Event Colors 的文档,您会看到有一个参数 className 您可以为每个事件对象指定。该参数的内容作为类添加到事件中,因此您只需指定具有匹配名称的 css。

    事件(注意 event1 上的 className 参数)

    [
      {
        title     : 'event1',
        start     : '2012-06-10',
        className : 'custom',
      },
      {
        title  : 'event2',
        start  : '2012-06-05',
        end    : '2012-06-07'
      },
      {
        title  : 'event3',
        start  : '2012-06-09 12:30:00',
        allDay : false
      }
    ]
    

    event1 看起来不同的 CSS

    .custom,
    .custom div,
    .custom span {
        background-color: green; /* background color */
        border-color: green;     /* border color */
        color: yellow;           /* text color */
    }
    

    点击此处http://jsbin.com/ijasa3/96 获取快速示例。请注意 event1 如何以绿色作为背景,以黄色作为文本颜色。


    使用 jQuery Fullcalendar Event Colors 中描述的选项的另一种可行方法可以按照以下方式进行:

    对需要另一种颜色的事件使用不同的事件源:

    $('#calendar').fullCalendar({
    ...
      eventSources: [
        //a full blown EventSource-Object with custom coloring
        {
          events: [  
            {
              title     : 'event1',
              start     : '2012-06-10'
            }
          ],
          backgroundColor: 'green',
          borderColor: 'green',
          textColor: 'yellow'
        },
        //a normal events-array with the default colors used
        [
          {
            title  : 'event2',
            start  : '2012-06-05',
            end    : '2012-06-07'
          },
          {
            title  : 'event3',
            start  : '2012-06-09 12:30:00',
            allDay : false
          }
        ]
      ],
      ...
    });
    

    http://jsbin.com/ijasa3/99

    【讨论】:

    • 哦,是的,我忽略了它,将检查是否可以通过 JSON 传递它。谢谢
    • 修复了 jsbin + 添加了另一个解决方案
    【解决方案2】:

    在 1.5 版本中,您可以在每个事件中设置 textColor、backgroudColor 和 borderColor。

    【讨论】:

      【解决方案3】:

      如果您升级到 1.5 版,您可能会发现这不起作用。解决方案似乎是注释掉样式

      .fc-event-skin { }
      

      【讨论】:

        【解决方案4】:

        为了更好的渲染,最好使用backgroundColorEventObject

        【讨论】:

          猜你喜欢
          • 2015-06-21
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多