Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I highlight a droppable area on hover using jquery ui draggable

I actually have two questions, the on in the title being the main one. I have multiple div elements on the page marked as droppable. Inside these div elements I have spans that are marked as draggable. I want it so when you are dragging an element and it is hovered over a droppable area that area either highlights or has a border so they know they can drop it there.

As secondary question, all my draggable elements have a display:block, a width and a float on them, so they look nice and neat in my droppable areas. When items are dropped they seem to get a position set to them as they no longer float nice and neat like the rest of my items. For reference, here is my javascript.

$('.drag_span').draggable({     revert: true }); $('.drop_div').droppable({     drop: handle_drop_patient });  function handle_drop_patient(event, ui) {     $(this).append($(ui.draggable).clone());     $(ui.draggable).remove(); } 
like image 948
Jhorra Avatar asked Mar 26 '12 20:03

Jhorra


People also ask

How do I limit a draggable area?

Limit draggable area using 'containment' option It is simple. All you have to do is, add an option called containment to the draggable() method. The containment option has a value parent.

How do you get the position of the draggable element?

The . position() method allows us to retrieve the current position of an element relative to the offset parent. Contrast this with . offset() , which retrieves the current position relative to the document.

What is droppable jQuery?

$ (selector, context). droppable (options) Method. The droppable (options) method declares that an HTML element can be used as an element in which you can drop other elements. The options parameter is an object that specifies the behavior of the elements involved.


1 Answers

Check out http://jqueryui.com/demos/droppable/#visual-feedback.

Ex:

$( "#draggable" ).draggable(); $( "#droppable" ).droppable({     hoverClass: "ui-state-active",     drop: function( event, ui ) {         $( this )             .addClass( "ui-state-highlight" )             .find( "p" )                 .html( "Dropped!" );     } }); $( "#draggable2" ).draggable(); $( "#droppable2" ).droppable({     accept: "#draggable2",     activeClass: "ui-state-hover",     drop: function( event, ui ) {         $( this )             .addClass( "ui-state-highlight" )             .find( "p" )                 .html( "Dropped!" );     } }); 
like image 107
j08691 Avatar answered Oct 13 '22 08:10

j08691