简体   繁体   English

嵌套的html5可拖动项

[英]nested html5 draggable items

I have a questions about html5 draggable items. 我对html5可拖动项有疑问。 I've been looking at this example: https://codepen.io/retrofuturistic/pen/tlbHE 我一直在看这个例子: https : //codepen.io/retrofuturistic/pen/tlbHE

If I customize it and make the parents draggable 如果我自定义它并使父母可拖动

<ul>
    <li draggable="true" class="parent-li">
        <ul id="columns-1">
            <li class="column child-li" draggable="true"><header>A</header></li>
            <li class="column child-li" draggable="true"><header>B</header></li>
        </ul>
    </li>
    <li draggable="true" class="parent-li">
        <ul id="columns-2" draggable="true">
            <li class="column child-li" draggable="true"><header>A</header></li>
            <li class="column child-li" draggable="true"><header>B</header></li>
        </ul>
    </li>
</ul>

it turns out that when you are trying to sort a list-item "child-li" it tries to drag "parent-li" 原来,当您尝试对列表项“ child-li”进行排序时,它会尝试拖动“ parent-li”

this.parentNode.removeChild(dragSrcEl);

the dragSrcEl is the same as this.parentNode: the "parent-li". dragSrcEl与this.parentNode相同:“ parent-li”。

So is it possible to sort the list-items as long as they're on the same level? 因此,只要列表项处于同一级别,是否可以对它们进行排序?

It was late yesterday. 昨天很晚。 I should use event.stopPropagation() to prevent bubbling up on parent elements. 我应该使用event.stopPropagation()来防止父元素冒泡。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM