[英]fullCalendar: set event background color to linear-gradient not working
the (newest) FullCalendar docu outlines, that "You can use any of the CSS color formats such #f00, #ff0000, rgb(255,0,0), or red." (最新的)FullCalendar 文档概述,“您可以使用任何 CSS 颜色格式,例如 #f00、#ff0000、rgb(255,0,0) 或红色。” as event background color ( https://fullcalendar.io/docs/eventBackgroundColor ).
作为事件背景颜色( https://fullcalendar.io/docs/eventBackgroundColor )。
Now I need to split the colors of the event into eg green and red, making green for the first 80% and red for the remaining 20% of the event duration.现在我需要将事件的颜色分成例如绿色和红色,将事件持续时间的前 80% 设为绿色,将事件持续时间的剩余 20%设为红色。 I found a linear-gradient solution, which works fine thanks to another SO topics and that would be a nice solution.
我找到了一个线性梯度解决方案,由于另一个 SO 主题,它可以很好地工作,这将是一个不错的解决方案。
However while "red" and "green" as single values work fine for the "backgroundColor" attribute, the linear-gradient does not change the event color like in this event below:然而,虽然“红色”和“绿色”作为单个值适用于“背景颜色”属性,但线性渐变不会像下面的这个事件一样改变事件颜色:
{
title: 'Long Event',
start: '2020-09-07',
end: '2020-09-10',
backgroundColor : 'linear-gradient(90deg, pink 80%, cyan 0%)'
}
At https://codepen.io/fendrikat/pen/mdPqjJq you have an example - the second event, "Long event" should be with two colors.在https://codepen.io/fendrikat/pen/mdPqjJq你有一个例子 - 第二个事件,“长事件”应该有两种颜色。
To use a class would not make sense, as the actual percentage and colors will differ for every event (one may be 30% yellow and 70% green, another 20% green and 80% red, another 27% and 73%, ...and so on), so I need to control this in the javascript code.使用类是没有意义的,因为每个事件的实际百分比和颜色会有所不同(一个可能是 30% 的黄色和 70% 的绿色,另一个 20% 的绿色和 80% 的红色,另一个 27% 和 73%,...... .等),所以我需要在javascript代码中控制它。
Anyone any thoughts how the linear-gradient can work for a FullCalendar event in backgroundColor ?任何人都知道线性渐变如何适用于 backgroundColor 中的 FullCalendar 事件?
Thanks a lot,非常感谢,
Frank坦率
The backgroundColor
cannot accept a gradient. backgroundColor
不能接受渐变。 This is equivalent to the background-color
property in CSS.这相当于 CSS 中的
background-color
属性。 Background color values can only be name, rgb, hsl, hex or any other standardized color value format.背景颜色值只能是名称、rgb、hsl、hex 或任何其他标准化颜色值格式。 If you want to set a gradient for the background, you will need to apply it to the
background
property of the element.如果要为背景设置渐变,则需要将其应用于元素的
background
属性。 This is not a supported property in FullCalandar.这不是 FullCalandar 支持的属性。 You will need to set the style property after the event is rendered to the calandar.
在将事件呈现到日历后,您需要设置 style 属性。
You can use eventDidMount
in version 5 of FullCalendar.您可以在
eventDidMount
版本 5 中使用 eventDidMount。 This is a replacement for eventRender
that was removed prior to version 5's release.这是在第 5 版发布之前删除的
eventRender
的替代品。 This was the suggested solution in the following issue on Gitlab .这是Gitlab 上以下问题中建议的解决方案。
/**
* FullCalandar v5+
*
* Where `background` is a non-standard event property,
* supplied by the event.
*/
eventDidMount: function (info) {
if (info.event.extendedProps.background) {
info.el.style.background = info.event.extendedProps.background;
}
}
document.addEventListener("DOMContentLoaded", function () { const calendarEl = document.getElementById("calendar"); const calendar = new FullCalendar.Calendar(calendarEl, { initialView: "dayGridMonth", initialDate: "2020-09-12", events: [ { title: "All Day Event", start: "2020-09-01" }, { title: "Long Event", start: "2020-09-07", end: "2020-09-10", // Non-standard property below background: "linear-gradient(90deg, pink 80%, cyan 0%)" } ], eventDidMount: function (info) { if (info.event.extendedProps.background) { info.el.style.background = info.event.extendedProps.background; } } }); calendar.render(); });
html, body { margin: 0; padding: 0; font-family: Arial, Helvetica Neue, Helvetica, sans-serif; font-size: 14px; } #calendar { max-width: 1100px; margin: 40px auto; }
<link href="https://cdn.jsdelivr.net/npm/fullcalendar@5.3.1/main.min.css" rel="stylesheet"/> <script src="https://cdn.jsdelivr.net/npm/fullcalendar@5.3.1/main.min.js"></script> <div id='calendar'></div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.