"Enhancing fullcalendar v2 by modifying the backgroundEvent to only display half of the first and

Currently utilizing fullcalendar.io v2.

Is there a way, through callbacks and/or jQuery, to split the first and last cell of a backgroundEvent in half like shown in the image attached? Or potentially apply a different CSS style to those cells?

https://i.sstatic.net/FfzzA.jpg

I am aware that I can render an Event with time included, but what I require is for allDay events to fill the background color of the table cell...

I attempted using eventRender but had no success... possibly because it's a backgroundEvent?!


        eventRender: function (event, element) {
            if (event.date === event.start) element.css('background-color', 'yellow');
        }
    

Answer №1

I successfully implemented it using the eventAfterAllRender callback method.

https://i.sstatic.net/3tRyv.png

eventAfterAllRender: function (view) {

jQuery.each($calendar.fullCalendar('clientEvents'), function () {
    
var event = this;
var $start = $calendar.find('td.fc-day[data-date="' + event.start.format('YYYY-MM-DD') + '"]');
var $end = $calendar.find('td.fc-day[data-date="' + event.end.format('YYYY-MM-DD') + '"]');

if (event.rendering === 'background') {

    if ($start.hasClass('fc-backgroundeventend')) {
        $start.removeClass('fc-backgroundeventend').addClass('fc-backgroundeventendstart');
    } else {
        $start.addClass('fc-backgroundeventstart'); 
    }

    for (var d = event.start.clone().add(1, 'day') ; d < event.end; d.add(1, 'day')) {
        $calendar.find('td.fc-day[data-date="' + d.format('YYYY-MM-DD') + '"]').addClass('fc-backgroundevent'); 
    }

    if ($end.hasClass('fc-backgroundeventstart')) {
        $end.removeClass('fc-backgroundeventstart').addClass('fc-backgroundeventendstart');
    } else {
        $end.addClass('fc-backgroundeventend'); 
    }
} // /event.rendering === 'background'
}); // /each

} // /eventAfterAllRender

In addition, I utilized the following CSS classes:

.fc-backgroundevent {
    background-color: #ff8a8a;
}

.fc-backgroundeventendstart {
    background: linear-gradient(135deg,  rgba(255,138,138,1) 49%,rgba(255,138,138,1) 49%,rgba(255,255,255,1) 49%,rgba(255,255,255,1) 49%,rgba(255,255,255,1) 51%,rgba(255,138,138,1) 51%,rgba(255,138,138,1) 51%);
}

.fc-backgroundeventstart {
    background: linear-gradient(to left top, #ff8a8a 50%, #FFFFFF 50%) !important;
}

.fc-backgroundeventend {
    background: linear-gradient(to right bottom, #ff8a8a 50%, #FFFFFF 50%) !important;
}

Furthermore, to achieve the desired effect, I had to adjust the background color of the backGroundEvent to transparent:

.fc-bgevent {
    background-color: transparent !important;
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Please send the element that is specifically activated by the onClick function

This is the HTML code I am working with: <li class="custom-bottom-list"> <a onClick="upvote(this)"><i class="fa fa-thumbs-o-up"></i><span>upvote</span></a> </li> Here is my JavaScript function for Upvot ...

What is the method for accessing a local CSV file using client-side Javascript?

I need to use client-side JavaScript to read data from a local csv file. The HTML code imports a JavaScript file located in a different folder using a script tag. Here's the content of the JavaScript file: $.ajax({ type: "GET", url: "./../.. ...

Setting a timeout for each individual jQuery element

I'm currently working on a jQuery function to dynamically change the href of a link, but I'm encountering some difficulties. The slider I've created is functioning properly, however, there is an outside link that needs to update its href bas ...

Tips on how to retrieve the current value of a scope variable in jQuery

When making a $http request to save data on the server and receiving a json response, I want to show an Android-style message using Toast for either success or failure based on the response. Initially, I set a scope variable to false $scope.showSuccessToa ...

What is the best way to automatically adjust the size of an image to fit its

One of the challenges with the parent container is fitting an image inside it: .parent { position: relative; text-align: center; overflow: hidden; display: flex; align-items: center; align-content: center; justify-content: cente ...

Bringing the value from the codebehind to the jquery function on the client side

Here is the code snippet from my asp.net web application's code behind where I have integrated another web service: [WebMethod] public static string GetData(string name) { WEBSERVICE.Service1 Client = new Service1(); string Nam ...

Is there a way to position an h3 next to a p without generating separate lines?

My html code appears like this: <h3>Corruption, the most infallible symptom of constitutional liberty.</h3> <p>~ Edward Gibbon</p> The output it generates is shown below: I have indicated with an arrow that I would prefer Edward ...

Ajax encountered an error while attempting to load the requested resource

jQuery('input').on('click',function(e){ $.getJSON( "/data.json", function(info){ var name = data.name; } ); }); Every time we click, a JSON request is supposed to be made. But unfortunately ...

Tips for adding an additional div inside a navigation container, evenly spacing objects, and aligning the search bar to the right

I'm currently working on designing a simple navigation bar but I'm facing difficulties in aligning the elements correctly. See my progress here: https://jsfiddle.net/zigzag/bL1jxfax/ Here are my objectives: 1) Ensure that the navigation bar rea ...

"Instant Elementor offers seamless CSS transitions for an enhanced user experience

UPDATE: Issue resolved, discovered that Elementor was overriding certain styles. Please refer to my solution below. I'm attempting to add animation to a simple max-height property of a div, but the transition isn't working as expected. It transi ...

What is the best way to ensure an image fills the entire space within a Bootstrap modal container?

I'm having some issues with my bootstrap modals that contain images. When the images are long vertically, a scrollbar appears which is not ideal. I tried to solve this by setting a max-height for the modal-content and making the modal-body (where the ...

"Trouble with Ajax success handler - it's not functioning properly

$.ajax({ type: 'GET', url: 'https://example.com/api/v1/data?access_token=[TOKEN]', cache: false, dataType: "jsonp", crossDomain: true, jsonp: false, success: function(response){ alert("Data retrieved ...

Placing a pseudoelement amidst the track and thumb of a range input type

I'm trying to position a pseudo element with a specific z index that is lower than the thumb of an input type range but higher than its track. This is what I have so far: HTML: <div class="range"> <input type="range" name="" class="progre ...

"Learn the step-by-step process of retrieving the height and width of a user's

Functional Fiddle: http://jsfiddle.net/nbv8mb4a/ Tested Fiddle: http://jsfiddle.net/3m0zekyj/ The working Fiddle I created allows users to preview an image before uploading it. My next goal is to determine the height and width of the image in order to sc ...

Steps for transforming an i18n.map into a JSON object

I have encountered an issue with my web app. It is designed to convert a json file into a table, but I am facing a problem when the file does not follow the expected format: i18n.map("it", { errors: { "cannot.fetch.credit":"Ops... non riesco a leggere il ...

Implement a shaking animation for a div when the input fields are not valid

Does anyone know how to make these divs shake when the inputs are not valid (or empty)? Here is a link to what I have tried so far: http://jsfiddle.net/jalxob/ahQLC/13/ I attempted to accomplish this by using: .effect('shake'); If anyone h ...

Troubleshooting issues with Bootstrap's responsiveness configuration

I've been working on creating a responsive user login page using Angular 5. It looks great on full-screen display. https://i.sstatic.net/YQrL5.png However, when I resize the browser window, the responsiveness seems to break. https://i.sstatic.net/4 ...

Having trouble with my browser freezing whenever I use PhoneGap in conjunction with jQuery Mobile

While developing my phoneGap app with jQuery Mobile integration, I encountered some issues. Before importing jQuery Mobile, my page was running normally. However, upon importing jQuery Mobile and running index.html, I started getting unexpected popups. Af ...

Identifying a span element and appending to its classList

I am currently working on code that generates spans, and my objective is to adjust the color of specific spans based on their text content. I have identified a section where I need assistance with the syntax of the code I should input. My aim is to locate ...

What is the best way to include a JavaScript function in a dynamically generated div?

By clicking a button, I am able to dynamically generate a table row that contains a div element with the class "contents." $(document).on("click", ".vote", function() { // Removing selected row var rowLoc = this.parentNode.parentNode. ...