如何在右键单击时更改fullcalendar事件的颜色 [英] How to change the color of a fullcalendar event on right click
问题描述
为了更改jQuery事件的颜色,右键单击使用上下文菜单,我从这里得到了一个帮助与最多的答案的答案。
In order to change the color of the jQuery event on right click using context menu , I got some assistance from here with the answer with the most votes.
< a href =http://stackoverflow.com/questions/4495626/making-custom-right-click-context-menus-for-my-web-app?answertab=active#tab-top>进行自定义右键单击我的网络应用程序的上下文菜单
但是,我想改变甚至在右键单击的颜色,所以这是我做了: -
However, I am trying to change the color of the even on right click so this is what I did :-
$(".custom-menu li").click(function(){
// This is the triggered action name
switch($(this).attr("data-action")) {
// A case for each action. Your actions here
case "red" :
//alert("RED");
$('#calendar').fullCalendar({
editable: false,
backgroundColor: "#800637"
});
break;
case "green":
$('#calendar').fullCalendar({
editable: false,
backgroundColor: "#00ff00"
});
break;
}
// Hide it AFTER the action was triggered
$(".custom-menu").hide(100);
});
右键单击自定义事件的HTML如下所示: -
And the HTML for the right click custom event looks like this :-
<ul class="custom-menu">
<li data-action="red" data-color="red">Red/Rouge</li>
<li data-action="green" data-color="green">Green/Verg</li>
</ul>
颜色变化的CSS类似如下:
And the CSS for the color change looks like this :
.red{
background-color: red;
}
.green{
background-color: green;
}
这是它的样子,但颜色不变。
完整日历视图
This is how it looks but at the moment the color does not change. Full Calendar view
推荐答案
这里是一个小提琴,你可以右键单击一个事件,并从菜单中选择一种颜色。
Here is a fiddle where you can right-click on an event and choose a color from the menu.
https://jsfiddle.net/uucm2c6m/
/*
Contains modified code from
http://stackoverflow.com/questions/4495626/making-custom-right-click-context-menus-for-my-web-app?answertab=active#tab-top
*/
$('#calendar').fullCalendar({
defaultDate: '2016-03-29',
events: [{
title: 'Right-click on me!',
start: '2016-03-29'
}],
});
// Trigger action when the contexmenu is about to be shown
$('a.fc-event').bind("contextmenu", function(event) {
// Avoid the real one
event.preventDefault();
// Show contextmenu, save the a.fc-event $(this) for access later
$(".custom-menu").data('event', $(this)).finish().toggle(100).
// In the right position (the mouse)
css({
top: event.pageY + "px",
left: event.pageX + "px"
});
});
// If the document is clicked somewhere
$(document).bind("mousedown", function(e) {
// If the clicked element is not the menu
if (!$(e.target).parents(".custom-menu").length > 0) {
// Hide it
$(".custom-menu").hide(100);
}
});
// If the menu element is clicked
$("ul.custom-menu li").click(function() {
// ul.custom-menu data has 'event'
var $event = $(this).parent().data('event');
// This is the triggered action name
var color = $(this).attr('data-color') || 'lightblue'; // Default to light blue
// Set the color for the event
// if the event has multiple sections (spans multiple weeks/days, depending on view)
// It will only change color of currently right-clicked section...
// See http://stackoverflow.com/questions/36128815/highlight-fullcalendar-events-that-expands-over-multiple-rows-columns/36185661
// for ideas on how to approach changing the color of all related sections if needed
$event.css('background-color', color);
// Hide it AFTER the action was triggered
$(".custom-menu").hide(100);
});
这篇关于如何在右键单击时更改fullcalendar事件的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!