[英]Function required from https://github.com/RubaXa/Sortable
I am using https://github.com/RubaXa/Sortable and i need to write an if/else function that can basically tell if you have dragged the right tile to the right target and if you haven't, bounce it back to where it came from (same order). 我正在使用https://github.com/RubaXa/Sortable ,我需要编写一个if / else函数,该函数基本上可以告诉您是否已将正确的图块拖动到正确的目标,如果尚未拖动,则将其反弹回它来自哪里(顺序相同)。
Pretty sure i use this event: Element is dropped into the list from another list 相当确定我使用了此事件:元素从另一个列表拖放到列表中
onAdd: function (/**Event*/evt) {
var itemEl = evt.item; // dragged HTMLElement
evt.from; // previous list
// + indexes from onEnd
},
First off, is evt a common parameter? 首先,evt是一个通用参数吗? (I am not a coder). (我不是编码员)。
Please find my working code here: https://codepen.io/maevemacn/pen/XMvZjP this does not include the external sortable.min.js file 请在这里找到我的工作代码: https : //codepen.io/maevemacn/pen/XMvZjP这不包括外部sortable.min.js文件
Any help greatly appreciated Maeve 任何帮助都非常感谢Maeve
How about something like this then? 那这样的事情怎么样? This is a minimal implementation of what I believe you're after. 这是我相信您所追求的最低限度的实现。
http://codepen.io/anon/pen/xdGoNe http://codepen.io/anon/pen/xdGoNe
onMove: function (evt, originalEvent) {
var textOfItemBeingDragged = evt.dragged.innerText.toLowerCase();
var destinationIndexOfTarget = evt.related.getAttribute('destination-index');
var areWeAllowedToDragToHere = allowedMappings[textOfItemBeingDragged] ==
destinationIndexOfTarget;
return areWeAllowedToDragToHere;
}
onMove does the interesting work - we check whether we're allowed to drop this item into the specific box onMove进行了有趣的工作-我们检查是否允许将此项目放入特定的框中
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.