【问题标题】:How do I change an event's background color with different colors, in fullcalendar?如何在全日历中使用不同颜色更改事件的背景颜色?
【发布时间】:2011-08-05 19:27:53
【问题描述】:

我正在使用fullcalendar 的最新版本,我查看了文档如何更改背景颜色事件,但我不知道如何制作不同的事件。
我需要带有红色、蓝色、绿色事件的代码示例,如下图所示:

我在文档站点上看到此代码,但我无法应用 2 种颜色:

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

【问题讨论】:

    标签: javascript jquery fullcalendar


    【解决方案1】:

    由于您使用的是最新版本(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 属性,也可以设置它。

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        【解决方案3】:

        我已经为每个事件应用了这样的颜色代码,它对我有用。

         $.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'       
                                 })   
        });             
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2017-05-05
          • 2015-06-21
          • 2016-03-16
          • 2019-09-27
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多