Jquery完整日历和动态事件颜色

时间:2010-03-14 09:17:39

标签: jquery fullcalendar

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

4 个答案:

答案 0 :(得分:41)

没有比这更容易的了。如果查看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中描述的选项的另一种可行方式可以遵循这些方针:

对需要其他颜色的事件使用不同的Eventsource:

$('#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

答案 1 :(得分:7)

使用1.5版,您可以在每个事件中设置文本颜色,背景颜色和边框颜色。

答案 2 :(得分:6)

如果升级到1.5版,您可能会发现这不起作用。解决方案似乎是评论风格

.fc-event-skin { }

答案 3 :(得分:2)

为了获得更好的渲染效果,最好使用backgroundColor的{​​{1}}。

相关问题