Javascript 将外部事件从滑动条拖动到FullCalendar
我在我的一个项目中同时使用slick slider和fullcalendar。完整日历提供了将外部事件拖动到日历的功能,如图所示。我无法实现相同的逻辑,因为我的事件位于slick滑块内。以下是我正在构建的内容的屏幕截图: 下面是代码:Javascript 将外部事件从滑动条拖动到FullCalendar,javascript,fullcalendar,slick.js,Javascript,Fullcalendar,Slick.js,我在我的一个项目中同时使用slick slider和fullcalendar。完整日历提供了将外部事件拖动到日历的功能,如图所示。我无法实现相同的逻辑,因为我的事件位于slick滑块内。以下是我正在构建的内容的屏幕截图: 下面是代码: <div class="menu-wrap"> <div class="tab-pane gallery container-fluid" id="favorites"> <div class="row d-n
<div class="menu-wrap">
<div class="tab-pane gallery container-fluid" id="favorites">
<div class="row d-none d-md-block gallery_wrapper">
<div class="w-100 d-none d-md-block heroSlider-fixed">
<div class="overlay">
</div>
<!-- Slider -->
<div class="slider responsive six">
@for($i=1;$i<=12;$i++)
@component('components.menu-plan-componant')
@endcomponent
@endfor
</div>
<!-- control arrows -->
<div class="prev six-prev">
<img src="{{URL::to('assets/images/icon/left_direction.svg')}}"
class="chevron-basic">
</div>
<div class="next six-next">
<img src="{{URL::to('assets/images/icon/right_direction.svg')}}"
class="chevron-basic">
</div>
</div>
</div>
</div>
</div>
完整日历的名称和代码:
$('#calendar').fullCalendar({
droppable: true,
defaultView: 'Week',
header: false,
defaultDate: today,
navLinks: false, // can click day/week names to navigate views
editable: true,
eventLimit: true, // allow "more" link when too many events
schedulerLicenseKey: 'GPL-My-Project-Is-Open-Source',
drop: function() {
// is the "remove after drop" checkbox checked?
if ($('#drop-remove').is(':checked')) {
// if so, remove the element from the "Draggable Events" list
$(this).remove();
}
},
eventRender: function (event, element) {
element.find(".fc-event-title").remove();
element.find(".fc-event-time").remove();
var new_description = '#';
element.append(new_description);
},
now: today,
footer: {
left: 'promptResource',
center: '',
right: ''
},
customButtons: {
promptResource: {
text: '+ add course',
click: function () {
var title = prompt('Course name');
if (title) {
$('#calendar').fullCalendar(
'addResource',
{title: title},
true // scroll to the new resource?
);
}
}
}
},
views: {
Week: {
type: 'timeline',
duration: {Days: '7'},
slotLabelInterval: {hours: 24},
slotDuration: {hours: 24},
}
},
resourceLabelText: 'Meal',
resourceRender: function (resource, cellEls) {
cellEls.on('click', function () {
if (confirm('Are you sure you want to delete ' + resource.title + '?')) {
$('#calendar').fullCalendar('removeResource', resource);
}
});
},
resources: [
{id: 'a', title: 'Breakfast', eventColor: 'red'},
{id: 'b', title: 'Lunch', eventColor: 'green'},
{id: 'c', title: 'Dinner', eventColor: 'orange'},
{id: 'd', title: 'Other', eventColor: 'grey'},
],
events: [
{id: '1', resourceId: 'b', start: today, end: today, title: 'event 1'},
{
id: '2',
resourceId: 'c',
start: '2018-04-07T05:00:00',
end: '2018-04-07T22:00:00',
title: 'event 2'
},
{id: '3', resourceId: 'd', start: '2018-04-06', end: '2018-04-08', title: 'event 3'},
{
id: '4',
resourceId: 'e',
start: '2018-04-07T03:00:00',
end: '2018-04-07T08:00:00',
title: 'event 4'
},
{
id: '5',
resourceId: 'f',
start: '2018-04-07T00:30:00',
end: '2018-04-07T02:30:00',
title: 'event 5'
}
],
drop: function() {
// is the "remove after drop" checkbox checked?
if ($('#drop-remove').is(':checked')) {
// if so, remove the element from the "Draggable Events" list
$(this).remove();
}
}
});
如何使用滑动条和完整日历实现事件拖放功能
更新:
如果我使slick内的元素可拖动,它只应用slick滑块内的区域,而不应用slick滑块外的区域。下面的屏幕截图显示了这一点:我成功地将Fullcalendar演示扩展为一个最小的示例,包括Slick。我使用了一个
setTimeout
来确保Slick在使任何东西都可拖动之前已经完成了dom操作,但我认为Slick提供了一些适当的异步事件,可以准确地告诉您它何时完成(没有检查文档)。我认为您可以将这个最小的设置调整到您自己的应用程序中
外部元素需要是可拖动的,如“jQuery UI可拖动”。查看Fullcalendar演示源代码的第15行:@FreemanLambda谢谢!但是代码笔链接是空的。你能检查一下吗?对不起,发错了笔链接。只需转到您在问题中发布的Fullcalendar演示,然后单击页面右上角的“在代码笔中编辑”按钮。@FreemanLambda是的,我使用了相同的笔,但它不适用于slick slider。我想拖放的元素在slick slider div中,这就是我发布这个问题的原因。也许这条线索会帮助你:谢谢!它可以工作,但现在的问题是,一旦事件离开光滑的滑块区域,它就会隐藏起来。是否有一种方法可以在拖动时显示事件。我认为这与滑块或日历的z索引有关。请编辑您的codepen示例好吗?隐藏事件不是因为z索引,而是因为封装所有事件的
.slick list
elment具有溢出:隐藏。这种隐藏的溢出是旋转木马运行所必需的,但同时,一旦内容离开.slick list
的边界,它就会使其中的任何内容(事件)不可见。因此,我看不到任何可能的方法使元素的拖动对用户可见。另外,是否可以在日历事件中显示配方图像(如屏幕截图所示)?我想做的是在完整的日历事件中呈现图像。是的,这是可能的,通过在eventRender
回调期间调整事件Dom。以下是方法:
$('#calendar').fullCalendar({
droppable: true,
defaultView: 'Week',
header: false,
defaultDate: today,
navLinks: false, // can click day/week names to navigate views
editable: true,
eventLimit: true, // allow "more" link when too many events
schedulerLicenseKey: 'GPL-My-Project-Is-Open-Source',
drop: function() {
// is the "remove after drop" checkbox checked?
if ($('#drop-remove').is(':checked')) {
// if so, remove the element from the "Draggable Events" list
$(this).remove();
}
},
eventRender: function (event, element) {
element.find(".fc-event-title").remove();
element.find(".fc-event-time").remove();
var new_description = '#';
element.append(new_description);
},
now: today,
footer: {
left: 'promptResource',
center: '',
right: ''
},
customButtons: {
promptResource: {
text: '+ add course',
click: function () {
var title = prompt('Course name');
if (title) {
$('#calendar').fullCalendar(
'addResource',
{title: title},
true // scroll to the new resource?
);
}
}
}
},
views: {
Week: {
type: 'timeline',
duration: {Days: '7'},
slotLabelInterval: {hours: 24},
slotDuration: {hours: 24},
}
},
resourceLabelText: 'Meal',
resourceRender: function (resource, cellEls) {
cellEls.on('click', function () {
if (confirm('Are you sure you want to delete ' + resource.title + '?')) {
$('#calendar').fullCalendar('removeResource', resource);
}
});
},
resources: [
{id: 'a', title: 'Breakfast', eventColor: 'red'},
{id: 'b', title: 'Lunch', eventColor: 'green'},
{id: 'c', title: 'Dinner', eventColor: 'orange'},
{id: 'd', title: 'Other', eventColor: 'grey'},
],
events: [
{id: '1', resourceId: 'b', start: today, end: today, title: 'event 1'},
{
id: '2',
resourceId: 'c',
start: '2018-04-07T05:00:00',
end: '2018-04-07T22:00:00',
title: 'event 2'
},
{id: '3', resourceId: 'd', start: '2018-04-06', end: '2018-04-08', title: 'event 3'},
{
id: '4',
resourceId: 'e',
start: '2018-04-07T03:00:00',
end: '2018-04-07T08:00:00',
title: 'event 4'
},
{
id: '5',
resourceId: 'f',
start: '2018-04-07T00:30:00',
end: '2018-04-07T02:30:00',
title: 'event 5'
}
],
drop: function() {
// is the "remove after drop" checkbox checked?
if ($('#drop-remove').is(':checked')) {
// if so, remove the element from the "Draggable Events" list
$(this).remove();
}
}
});