发布于 2023-09-21 11:22:55 浏览 149
<div id="myDiv" draggable="true">
拖拽我
</div>
#myDiv {
width: 200px;
height: 200px;
background-color: lightblue;
cursor: move;
}
var myDiv = document.getElementById("myDiv");
myDiv.addEventListener("dragstart", function(event) {
event.dataTransfer.setData("text/plain", event.target.id);
});
myDiv.addEventListener("dragover", function(event) {
event.preventDefault();
});
myDiv.addEventListener("drop", function(event) {
event.preventDefault();
var data = event.dataTransfer.getData("text/plain");
var draggedElement = document.getElementById(data);
draggedElement.style.left = event.clientX + "px";
draggedElement.style.top = event.clientY + "px";
});
CSS基础 发布于 2023-09-19 22:25:58 浏览 188
其他 发布于 2023-08-23 18:21:50 浏览 187
PHP基础 发布于 2023-08-22 17:08:30 浏览 195
PHP基础 发布于 2023-08-22 15:31:40 浏览 185
WORD基础 发布于 2023-06-10 00:10:19 浏览 421
CSS基础 发布于 2022-12-18 15:59:29 浏览 549
WPS基础 发布于 2022-12-18 13:52:35 浏览 332
PS基础 发布于 2022-11-23 20:34:52 浏览 543