jquery - 拖动元素并滚动到顶部使元素保持在其位置,但光标会改变位置
问题描述
我将 Fullcalendar 与调度程序一起使用。当我尝试将事件从事件列表拖动到日历时 - 它工作正常,但是当我拖动它,然后使用滚动时 - 事件停留在您将其拖动到的位置,并且光标会根据滚动。所以,这是我的代码:
$('#external-events .fc-event').each(function() {
// store data so the calendar knows to render an event upon drop
$(this).data('event', {
title: $.trim($(this).text()), // use the element's text as the event title
stick: true // maintain when user navigates (see docs on the renderEvent method)
});
// make the event draggable using jQuery UI
$(this).draggable({
cursorAt: {
left: 5,
top: 5
},
zIndex: 999,
refreshPositions: true,
revert: true, // will cause the event to go back to its
revertDuration: 0 // original position after the drag
});
});
#external-events {
width: 100%;
height: 850px;
overflow-y: auto;
overflow-x: hidden;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.css" />
<section id="calendar"></section>
<section id="external-events">
<div class="fc-event event-to-drop">
<p>Some content here</p>
</div>
<div class="fc-event event-to-drop">
<p>Some content here</p>
</div>
</section>
我尝试了我在互联网上找到的解决方案(用容器包装,并赋予它position: relative;
样式、appendTo: 'body', helper: 'clone'
属性等),但它对我没有帮助。我可以用其他方法来解决这个问题吗?谢谢。
解决方案
推荐阅读
- excel - 如何对超过三列进行排序?
- reactjs - 反应材料-ui链接
- javascript - 如何使用带有 if else 语句的 javscript 显示多个下拉列表?
- javascript - 用另一个数组中相应位置的数字替换数字数组中的零
- networking - 外部 ips 应该如何在 OpenShift (4.x) 中工作?
- amazon-web-services - 在同一区域内使用预签名 URL 将文件从 S3 下载到 EC2 的成本
- android - 将缩略图设置为“VideoView”的 Android 代码
- javascript - JavaScript 中的调用堆栈优先级
- javascript - Vuex中未定义的ReferenceError
- c# - 尝试获取模板绑定样式以更新背景颜色