拖动DOM元素时有什么方法可以更改光标样式

Is there any way to change the cursor style when dragging DOM element?

本文关键字:光标 样式 方法 元素 DOM 什么 拖动      更新时间:2023-09-26

我有一个draggable = true的 DOM 元素,我想在拖动此元素时更改默认光标样式。

以下是一些代码:

function dragstart(e){
    element.style.cursor = 'move';
}
element.addEventListener('dragstart', dragstart, false);

请注意:不仅仅是像使用 css 的图像自定义光标一样。

有什么办法吗?

使用e.target

function dragstart(e){
     e.target.style.cursor = "move";
    }

尝试使用 jQuery

function dragstart(e){
 $(this).css("cursor","move");
}