简体   繁体   English

拖放 HTML5

[英]Drag and Drop HTML5

Folks, how can i update the styles of dragged element伙计们,我如何更新拖动元素的 styles

  1. Update the element which is under drag更新被拖动的元素
  2. Update the position/space from where the element was dragged更新拖动元素的位置/空间

it seems that using似乎使用

event.target.addClass or event.target.styles.  etc

updates the element which is under drag as well as position from where it was taken更新被拖动的元素以及 position 从它被采取的地方

please take a look at this screenshot link , this is what i want to achieve when dragging the element, basically onDragStart请看一下这个截图链接,这是我在拖动元素时想要实现的,基本上是onDragStart

thank you谢谢你

With this you can change style of element being dragged and keep the original style (or change it the way you like):有了这个,您可以更改被拖动元素的样式并保持原始样式(或以您喜欢的方式更改):

 function handleDragStart(e) { this.style.color = 'red'; } function handleOnDrag(e) { this.style.color = 'black'; } let items = document.querySelectorAll('ul>li'); items.forEach(function(item) { item.addEventListener('dragstart', handleDragStart, false); item.addEventListener('drag', handleOnDrag, false); });
 <ul> <li draggable="true">lorem ipsum</li> <li draggable="true">lorem ipsum</li> <li draggable="true">lorem ipsum</li> </ul>

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

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