How do I change an event's background color with different colors, in fullcalendar?

。_饼干妹妹 提交于 2019-12-02 20:59:29

Since you are using the latest version (1.5), you can set the backgroundColor property.

{
  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'
}   

You can also set the textColor property if you need to change that as well.

Use css and the className property.

<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>

I have applied the color code like this for each event, It works for me.

 $.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'       
                         })   
});             
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!