gpt4 book ai didi

javascript - 将光标更改为 'move' 上的 'dragstart'

转载 作者:行者123 更新时间:2023-12-01 16:17:34 26 4
gpt4 key购买 nike

我试图在拖动开始后将光标更改为“移动”。我尝试将 dropEffect 属性设置为 move 但这不起作用。 https://developer.mozilla.org/en-US/docs/Web/API/HTML_Drag_and_Drop_API

如何仅在 dragstart 事件触发后将 cursor 更改为 move

const button = document.querySelector("button");
console.log(button);

button.addEventListener("dragstart", dragStart);

function dragStart(e) {
e.dataTransfer.setData("text/plain", 'hello');
e.dataTransfer.dropEffect = "move";
console.log(e);
}
<button type="button" draggable="true">Drag Me</button>

最佳答案

据我所知,dropEffect 仅在用户将鼠标悬停在放置目标 上时可用:

Within event handlers for dragenter and dragover events, dropEffect should be modified if a different action is desired than the action that the user is requesting.

MDN

它说 dragenterdragover 但不是 dragstart

关于javascript - 将光标更改为 'move' 上的 'dragstart',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62156613/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com