简体   繁体   English

HTML 5拖放 - 使用自定义光标

[英]HTML 5 drag drop - Using custom cursor

I am actually trying to use a custom cursor when dragover operation of HTML 5 Drag-drop API is happening, but I am not able to do override the default cursor when dragover event is triggered. 我实际上在HTML 5 Drag-drop API的dragover操作时尝试使用自定义光标,但是当触发dragover事件时,我无法覆盖默认光标。 Here is the code of how I try to achieve it, 这是我试图实现它的代码,

$("#myDiv").live('mousedown', function(ev) {
  $(this).css("cursor", "url(res/customCursor.cur), default !important");
});

Since the mouse would be pressed when dragover event is happening, I try to change cursor in mousedown event of the target of drag-drop. 由于在dragover事件发生时会按下鼠标,我会尝试在拖放目标的mousedown事件中更改光标。 I also have tried to change the cursor in event handler of dragover event, but even that doesn't work. 我也尝试在dragover事件的事件处理程序中更改游标,但即使这样也行不通。

In your stylesheet definitions (<style> element or .css file) create a class like 在样式表定义(<style>元素或.css文件)中创建一个类

.dragAndDropInProgress {
  cursor: url(....), default !important; 
}

and then when you signal the ondragstart, attach that class to the document body, making sure to remove it again once you see the ondragend. 然后当您发出ondragstart信号时,将该类附加到文档正文,确保在看到ondragend后再将其删除。

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

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