拖放实时移动



如何使用html拖放api和纯js来实现这种效果 https://stackblitz.com/angular/pldxjeolvdy?file=app%2Fcdk-drag-drop-overview-example.ts

总之,使元素实时移动(不是默认的阴影效果(。

我试图在dragover事件中使用相同的drop((方法,但失败了。所以我在网上搜索,似乎我们无法在拖累事件中获得 e.dataTransfer.getData('text'(。

HTML5拖放屏幕上的任何位置使用此答案我可以移动div,但它不像我附加的示例那样实时

如果你想用更少的代码来解决这个问题,你可以使用 jQuery Uidraggable();函数实时移动任何元素。

$( function() {
$("#drag").draggable();
} );
#drag {
width: 150px;
height: 150px;
padding: 10px; 
z-index:9;
cursor: all-scroll;
color:#fff;
background-color: green;
}
.other{
width:90%;
position:relative;
padding: 10px;
background-color: red;
color:#fff;
z-index: 0;
margin-top:10px;
}
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Draggable element</title>
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
</head>
<body>

<div id="drag" class="ui-widget-content">
Drag this div
</div>
<div class="other">
<h4>Other elements </h4>
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.
</div>

</body>
</html>

最新更新