如何在fullcalendar中使用不同的颜色更改事件的背景颜色?

16
我正在使用最新版本的fullcalendar,我查看了文档,想要改变事件的背景颜色,但我不知道如何使不同的事件有不同的颜色。我需要一个包含红、蓝、绿三种颜色事件的代码示例,就像下面的图片。

enter image description here

我看到了在文档网站上的这段代码,但我不能应用两个颜色:
$('#calendar').fullCalendar({
  editable: true,
  events: [{
    title: 'Teste1',
    start: new Date(y, m, d, 10, 30),
    allDay: false,
    editable: false
  }, {
    title: 'Teste2',
    start: new Date(y, m, d, 11, 40),
    allDay: false
  }],
  eventColor: '#378006'
});
4个回答

33

由于您正在使用最新版本(1.5),因此可以设置 backgroundColor 属性。

{
  title: 'Teste1',
  start: new Date(y, m, d, 10, 30),
  allDay: false,
  editable: false,
  backgroundColor: '#SomeColor'
},
{
  title: 'Teste2',
  start: new Date(y, m, d, 11, 40),
  allDay: false,
  backgroundColor: '#SomeOtherColor'
}   

如果您需要更改文本颜色,也可以设置textColor属性。


12

使用CSS和className属性。

<style>
.event {
    //shared event css
}

.greenEvent {
    background-color:#00FF00;
}

.redEvent {
    background-color:#FF0000;
}
</style>

<script>
$('#calendar').fullCalendar({
      editable: true,             events: [
          {
              title: 'Teste1',
              start: new Date(y, m, d, 10, 30),
              allDay: false,
                editable: false,
              className: ["event", "greenEvent"]
          },
          {
              title: 'Teste2',
              start: new Date(y, m, d, 11, 40),
              allDay: false,
              className: ["event", "redEvent"]
          }           ], eventColor: '#378006'        });
</script>

0
我已经为每个事件应用了这样的颜色代码,这对我有效。
 $.each(data, function(i, v){    
    var event =[];     
    var col = "";           
                            if(v.Status == 1)      
                            {  
                                col = "#00c0ef";  
                            }  
                            else if(v.Status == 2){  
                                col = "#dd4b39";  
                            }     
                            else if (v.Status === 3)  
                            {    
                                col = "#f39c12";   
                            }       
                            else {   
                                col = "#00a65a";  
                            }    
                         event.push({   
                             title: v.AssignedName + "\n  Installation Date: \n" + da,    
                             start: da,    
                             backgroundColor: col,    
                                textColor:'black'       
                         })   
});             

0
eventContent: function(arg) {                            
  var sln = arg.event.title.substring(0, 1);          
  switch(sln) {
    case '1':
      arg.backgroundColor='#198754';
      break;
    case '2':
      arg.backgroundColor='#adb5bd';            
      break;
    case '3':
      arg.backgroundColor='#ffc107';            
      break;
    case '4':
      arg.backgroundColor='#6f42c1';            
      break;
    default:
      //
  }
}

你的回答可以通过添加更多关于代码的信息以及它如何帮助提问者来改进。 - Tyler2P

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接