HTML5 Drag & Drop change cursor while dragging (don't use UI)

安稳与你 提交于 2019-12-10 17:20:18

问题


I want to change the cursor when dragging, so I try this way:

function drag (event) {

    localStorage.setItem("no", $(event.target).data("no"));

    $("html").css("cursor", "move");

}
<tr draggable="true" class="memo_item move" id="memo_<?php echo $memo->memo_no?>" ondragstart="drag(event, this);" data-no="<?php echo $memo->memo_no?>"></tr>

but it doesn't work.

And I can't use JQueryUi.

How can I change cursor?


回答1:


Simply implement this kind of event setup in your code...

$('<some element here>').on('dragstart', function() {
  $(this).css("cursor", "move");
});

However, this will permanently change the cursor on the element, to toggle this cursor change add

$('<some element here>').on('dragend', function() {
  $(this).css("cursor", "default"); // or whatever pointer you want to revert to
});


来源:https://stackoverflow.com/questions/27811009/html5-drag-drop-change-cursor-while-dragging-dont-use-ui

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!