FullCalendar - Images as events

前端 未结 2 1657
误落风尘
误落风尘 2021-01-13 04:16

Looking to use Full Calendar and to include images as events and draggable. In short, would love to see how this example https://fullcalendar.io/js/fullcalendar-3.0.1/demos/

2条回答
  •  说谎
    说谎 (楼主)
    2021-01-13 04:47

    In version Fullcalendar 5 or newer eventRender is no longer used, instead used eventContent Full code:

    document.addEventListener('DOMContentLoaded', function() {
                var calendarEl = document.getElementById('calendar');
                var calendar = new FullCalendar.Calendar(calendarEl, {
                  initialView: 'dayGridMonth',
                  events: [
                    {
                      title: '',
                      start: '2020-09-02',
                      image_url: 'images/demo/event-calendar-1.png',
                    },
                    {
                      title: '',
                      start: '2020-09-02',
                      image_url: 'images/demo/event-calendar-2.png',
                    },
                    {
                      title: 'Event',
                      start: '2020-09-17',
                      image_url: 'images/demo/event-calendar-1.png',
                    },
                    {
                      title: '',
                      start: '2020-09-19',
                      image_url: 'images/demo/event-calendar-3.png',
                    },
                    {
                      title: 'Hello',
                      start: '2020-09-28'
                    },
                  ],
                  eventContent: function(arg) {
                    let arrayOfDomNodes = []
                    // title event
                    let titleEvent = document.createElement('div')
                    if(arg.event._def.title) {
                      titleEvent.innerHTML = arg.event._def.title
                      titleEvent.classList = "fc-event-title fc-sticky"
                    }
        
                    // image event
                    let imgEventWrap = document.createElement('div')
                    if(arg.event.extendedProps.image_url) {
                      let imgEvent = ''
                      imgEventWrap.classList = "fc-event-img"
                      imgEventWrap.innerHTML = imgEvent;
                    }
        
                    arrayOfDomNodes = [ titleEvent,imgEventWrap ]
        
                    return { domNodes: arrayOfDomNodes }
                  },
                });
                calendar.render();
     
             });
    

提交回复
热议问题