我想通过我的 json 事件源为 jquery fullcalendar 传递事件的颜色,我该如何实现?
4 回答
没有比这更容易的了。如果您查看 jQuery Fullcalendar Event Colors的文档,您会看到className
可以为每个事件对象指定一个参数。该参数的内容作为类添加到事件中,因此您只需要指定具有匹配名称的 css。
事件(注意className
event1 上的参数)
[
{
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
}
]
让 CSSevent1
看起来不一样
.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 如何以绿色作为背景,以黄色作为文本颜色。
Another viable way using the options described in jQuery Fullcalendar Event Colors could go along these lines:
Use different Eventsources for the events which need another color:
$('#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
}
]
],
...
});
With version 1.5 you can set textColor, backgroudColor and borderColor in each event.
If you upgrade to version 1.5 you may find this does not work. The solution appears to be to comment out the style
.fc-event-skin { }
For a better rendering, it is better to use backgroundColor
of the EventObject
.