2016-03-29 121 views
2

コンテキストメニューを使用して右クリックしたときのjQueryイベントの色を変更するには、ここから最も多くの票を得て回答しました。右クリックでfullcalendarイベントの色を変更するには

Making custom right-click context menus for my web-app

しかし、私も右クリックでの色を変更しようとしていますと、これは私がやったことです: -

$(".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は次のようになりますこれは: -

<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は次のようになります。

.red{ 
    background-color: red; 
} 

.green{ 
    background-color: green; 
} 

これは見た目ですが、現時点では色は変わりません。 Full Calendar view

+0

'、}'私はあなたがアレックスを何を意味するかわからない偽構文 – Alex

+0

のですか? –

+0

彼は、javascriptのオブジェクト表記は '、}'で終わることはできないことを意味します。リテラル表記のオブジェクトの最後のプロパティ値は、コンマを使用しないでください。最後のカンマ( "green"と "#800637"の後)を削除すると、構文が正しくなります。 ;-) – Jeroen

答えて

0

ここでは、イベントを右クリックしてメニューから色を選択することができます。

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); 
}); 
+0

私はこれを試してみましょう... bidingがfc-eventで何の理由でも動作しないため、コンソールログにも何のエラーも与えないので、動作すればあなたに5つの星を与えます。 –

+0

フィドルは、JSコードをDOMで処理できるように処理します。 Firefox、Chromium、IE10で試してみましたが、うまくいきました。イベントを右クリックするとメニューが表示され、イベントの背景を変更するための色をクリックしてください – smcd

+0

これは特定のイベントのためですが、動的かどうかを確認してください。 –

関連する問題