Rajagopal
Rajagopal

Reputation: 991

Jquery Draggable Placeholder

I want to have a placeholder to be displayed when i drag items into the droppable container as like the placeholder displayed in JQuery Sortable.

We have a placeholder option in JQuery sortable. Is there anything similar to this in JQuery draggable method or anyway how can i make that.

Any suggestions will be helpful.

Upvotes: 4

Views: 9085

Answers (3)

Albert Rannetsperger
Albert Rannetsperger

Reputation: 934

Assuming your parent elements have IDs, here's some code from a recent project I did at work which worked for me:

$('#container').draggable({
    start: function(event, ui) {
        $('#' + ui.helper.context.id).addClass('active');
    },
    stop: function(event, ui) {
        $('#' + ui.helper.context.id).removeClass('active');
    }
})

Even without an ID you can probably get it to work. Hope this helps :)

Upvotes: 0

sathish
sathish

Reputation: 800

try below code,

As you mentioned, "container will have many elements". I assume those container will have 'div' elements.

$("#container_drop div").droppable({
    drop: function (event, ui) {
        $( this ).addClass( "ui-state-highlight" );
    },
    over: function (event, ui) {
        $( this ).addClass( "ui-state-highlight" );
    },
    out: function (event, ui) {
        $( this ).removeClass( "ui-state-highlight" );
    }
});

Upvotes: 1

sathish
sathish

Reputation: 800

Try the blow code,

$( "#container_drag" ).draggable({

      drag: function() {
        $('#container_drop').addClass('highlight_container');
      },
      stop: function() {
        $('#container_drop').removeClass('highlight_container');
      }

});

Where, container_drag - your draggable container and container_drop - where the items going to be dropped.

And in Css,

.highlight_container{border:...,background:...}

Upvotes: 0

Related Questions