javascript 拖动时更改光标
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16259638/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Changing cursor while dragging
提问by Surfine
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');
}
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
编辑:注意:我的小项目支持 html-5 drag and drop
,所以我需要能够在拖动带有 html-5 的 div 时更改光标drag attribute
回答by john Smith
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.
“不允许”光标只是表明根本没有可拖动的。你必须使用.draggable()
方法http://api.jqueryui.com/draggable/绑定你的 img
它有它自己的选项,用于在拖动时使用特定的光标。
you can use it as easy like
你可以像使用它一样简单
$( "#drag1" ).draggable({ cursor: "pointer" });
回答by Roman Pokrovskij
Yes it is possible. You should change the cursor of item that you are dragging (not the destination one).
对的,这是可能的。您应该更改要拖动的项目的光标(而不是目标项目)。