suqub
suqub

Reputation: 81

jQuery drop dragged element into many div's

I try to drop dragged div into, for example, 3 div's.

enter image description here

I want to drop blue rectangle on 3 divs. When rectangle is dropped 3 div's have to change backgroud. I try to do this with draggable and droppable but it work only on to one element :(

$(function() {
    $( ".event" ).draggable( { 
        grid: [ 5, 0 ],
        containment: "parent"
        }).resizable({ 
            containment: "parent",
            grid: [ 5, 0 ],
            maxHeight: 40,
            maxWidth: 1000,
            minHeight: 40,
            minWidth: 60,
            handles: 'e, w',
            resize: function( event, ui ) {
                $( "#event" ).css("background-color", "blue");
            }
        });

        $( ".eventPeriod" ).droppable({
            activeClass: "ui-state-hover",
            hoverClass: "ui-state-active",
            drop: function( event, ui ) {
                $( this )
                    .addClass( "ui-state-highlight" );
                    return false;
            }
        });
});

Any idea?

Upvotes: 0

Views: 68

Answers (1)

Julien Grégoire
Julien Grégoire

Reputation: 17124

You change the tolerance of your droppable. Like this:

     $( ".eventPeriod" ).droppable({
            tolerance: 'touch',
            activeClass: "ui-state-hover",
            hoverClass: "ui-state-active",
            drop: function( event, ui ) {
                $( this )
                    .addClass( "ui-state-highlight" );
                    return false;
            }
        });

Upvotes: 0

Related Questions