Changing cursor while dragging

梦想与她 提交于 2020-06-25 17:21:16

问题


Is it possible to change the cursor while dragging? I have been searching and trying to do it for a while now. I want to change the 'not-allowed' cursor which shows up while you drag an object to another cursor.

I tried creating an event and assigning it to the image I wanted to drag:-

<img id="drag1" class="drag" src="http://www.surfixe.com/img/tick2.png" draggable="true" ondragstart="drag(event)" />

java:-

function drag(ev) {
    $('#drag1').css('cursor', 'pointer');
}


jsfiddle

Edit: Note: My little project is suppost to be html-5 drag and drop, so I need to be able to change the cursor while dragging a div with html-5 drag attribute


回答1:


The 'not-allowed' cursor simply showed that there´s been no draggable at all. You have to bind your img with .draggable() method http://api.jqueryui.com/draggable/ it has it´s own option for a specific cursor to be used while dragging.

you can use it as easy like

$( "#drag1" ).draggable({ cursor: "pointer" });

http://jsfiddle.net/wpcbM/3/




回答2:


Yes it is possible. You should change the cursor of item that you are dragging (not the destination one).



来源:https://stackoverflow.com/questions/16259638/changing-cursor-while-dragging

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