admin管理员组文章数量:1414621
I have a page with multiple dragula containers. The containers are ul
's with a bunch of li
in them. I would like users to be able to reorder li
's in their containers, but I don't want the li
from one containers to be draggable to another container. Right now I can drag every li
to any ul
. How do I restrict the li
's only to their original containers?
html:
<ul id="first">
<li>for first group only</li>
<li>for first group only</li>
<li>for first group only</li>
</ul>
<ul id="second">
<li>for second group only</li>
<li>for second group only</li>
<li>for second group only</li>
</ul>
<ul id="third">
<li>for third group only</li>
<li>for third group only</li>
<li>for third group only</li>
</ul>
js:
var first = '#first';
var second = '#second';
var third = '#third';
var containers = [
document.querySelector(first),
document.querySelector(second),
document.querySelector(third)
];
dragula({
containers: containers,
revertOnSpill: true,
direction: 'vertical'
});
Thank you
I have a page with multiple dragula containers. The containers are ul
's with a bunch of li
in them. I would like users to be able to reorder li
's in their containers, but I don't want the li
from one containers to be draggable to another container. Right now I can drag every li
to any ul
. How do I restrict the li
's only to their original containers?
html:
<ul id="first">
<li>for first group only</li>
<li>for first group only</li>
<li>for first group only</li>
</ul>
<ul id="second">
<li>for second group only</li>
<li>for second group only</li>
<li>for second group only</li>
</ul>
<ul id="third">
<li>for third group only</li>
<li>for third group only</li>
<li>for third group only</li>
</ul>
js:
var first = '#first';
var second = '#second';
var third = '#third';
var containers = [
document.querySelector(first),
document.querySelector(second),
document.querySelector(third)
];
dragula({
containers: containers,
revertOnSpill: true,
direction: 'vertical'
});
Thank you
Share Improve this question asked Jan 23, 2017 at 11:18 Loading...Loading... 91310 silver badges25 bronze badges1 Answer
Reset to default 6You could specify an options.accepts method to check that the element is dragged to the same container it came from.
For example:
js:
dragula({
containers: containers,
revertOnSpill: true,
direction: 'vertical',
accepts: function (el, target, source, sibling) {
// accept drags only if the drop target is the same
// as the source container the element came from
return target == source;
}
});
本文标签:
版权声明:本文标题:javascript - Multiple containers with Dragula, but restrict items to only their container - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745160339a2645410.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论