How do i change the default drag and drop cursor? - javascript

I use a simple JavaScript drag and drop system.
However I want to change the default drag and drop move cursor
to another cursor like the pointer for example:
How can I change the looks of my drag and drop cursor? I tried setting the cursor css on body:hover with no effect and some other things.
There must be a relatively simple solution right? What am I missing?

Related

Animation take place during drag

I have an element that is draggable using jQuery UI's .draggable(), but I want it to follow a certain path while dragging.
In fact, while it is being dragged the whole layout of the page will be changing.
Since I have one set of styles for how the page looks like before the drag and one set of styles of how the page looks like after the drag is done, I figured using a CSS animation would make sense.
So, now, my question is how can I make that animation occur as the drag is happening?
Or if there is another way to do this then an animation, how can I transition from one style to another as a drag is happening.
What I'm trying to do is get the draggable element to drag into its place in the second styles.

Is it possible to disregard the standard drag and drop cursors during an HTML drag operation?

I am using the HTML drag and drop API to facilitate the resizing of columns in a table. When the user starts to drag a column, though, the cursor changes to one of the standard drag and drop effects (move, none, etc). I'd like the cursor to remain the way it was before the drag event was initiated. Is this possible using the drag and drop events, or will I have to fake the drag and drop using other events like click and mousemove?
you can do this with css
.elementClass {
cursor: normal;
}

How to create a move handle using jquery

This is more the theoretical type of question.
In my web-application i want to create a button that the user can click and therefore initiate a move-mode during which (until the mouse is released) all the mouse movements are being translated onto a certain DIV.
To better understand what i mean, think of a box in which to show a portion of an image (box is overflow:hidden) - i want to make it possible to move the image around within the box, but not by directly dragging the image, but by dragging a handle instead (a handle that does not move when dragged)
In the optimum case the mouse cursor hides while the drag operation is on.
My basic idea was to use a draggable but i got no clue on how to make it accessible, yet invisible.
How would i accomplish that using javascript/jQuery?
Making the cursor invisible isn't too difficult, see the top two answers on this question.
As for the handle, you could try using jQuery UI Draggable's handle option. The key to making the handle appear stationary is to have a separate element that looks like the handle, and position the real handle (which would be an empty element) on top of it.
You would then position the real handle back where it was, covering the fake handle, when the stop() event is fired.
So, in the start() event, you would add a class to the real handle that makes the cursor invisible (using either of the methods in the post mentioned earlier), and remove that class when the stop() event fires, causing the cursor to reappear.
The easiest approach would probably be to just apply different CSS styles on the click event of the button.
Add a class to your element (on click) for the :hover pseudo-class that has cursor: move; for its style and has cursor: none; for the :active pseudo-class. You could then have these styles removed once the user's mouse left the draggable area.
On click the function might look like this:
$('#myButton').click(function(){
$('#myDraggableElement').addClass('draggable');
});
$('#myDraggableElement').mouseLeave(function(){
$(this).removeClass('draggable');
});
Have I understood the question correctly?

How to turn off element CSS background when dragged

I've build a drag and drop interface using JavaScript where users can click and drag a link (that sometimes has a CSS background image) and drop it onto the canvas.
My problem is that the mouse cursor has the link background image beneath it during dragging. I need to add my own cursor design, so is there any way to turn this CSS background off so that it doesn't follow the mouse upon dragging?
have you tried setting :active pseudo class for anchor tags?
http://www.w3schools.com/cssref/sel_active.asp
then if that isn't work quite yet you could use !important after your deceleration possibly?
and example could be
.links:active {
background-image: none !important;
}
when the user releases the background image should return.
The best solution I found for this problem was to use jQuery to assign e.preventDefault() to the click event of the link, thus disabling the background drag effect. Then, if you want a custom cursor upon dragging, write a script to match an absolutely positioned div's (with the image as the background) x,y cords to the mouse position.

HTML5 svg drag and drop - how to?

I'm trying to create a framework for HTML5-based adventure/point and click games, and I want to start with creating a way of dragging objects (from screen to hotspots or inventory, from inventory to hotspots, etc.), with svg representing both objects and hotspots (ie. completely transparent shapes there to detect hits). The idea is to drag the item, and allow it to drop only if the mouse is touching the hotspot.
I've run into some problems. Firstly, assigning a draggable attribute to <svg> or the testing circle didn't work. I tried putting it in a <div>, but while the drag event did register and fire, the ghost image didn't show like in the html5rocks demos. How can I fix the dragging?
Here's the fiddle.

Categories