最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Changing cursor while dragging - Stack Overflow

programmeradmin3浏览0评论

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=".png" draggable="true" ondragstart="drag(event)" />

JavaScript:-

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

jsfiddle

Edit: Note: My little project is supposed 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

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./img/tick2.png" draggable="true" ondragstart="drag(event)" />

JavaScript:-

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

jsfiddle

Edit: Note: My little project is supposed 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

Share edited Dec 30, 2021 at 14:18 General Grievance 5,04338 gold badges37 silver badges56 bronze badges asked Apr 28, 2013 at 4:33 SurfineSurfine 3922 gold badges5 silver badges15 bronze badges 1
  • I have the same problem. Did you ever find any solution? Here is a duplicate link stackoverflow./questions/14930811/… – Ricky Jiao Commented Apr 1, 2016 at 15:46
Add a ment  | 

2 Answers 2

Reset to default 2

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./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/wpcbM/3/

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

发布评论

评论列表(0)

  1. 暂无评论