jquery sortable and droppable - cannot append the drop item?

谁说胖子不能爱 提交于 2019-12-11 15:27:59

问题


I want to append the dropped item into the targeted droppable box from the sortable list, but I cannot append the dropped item into the specific element.

My jquery,

$(".sortable").sortable({
    update: function(){
    // php update.
    }
}).disableSelection();


$( ".droppable" ).droppable({
    activeClass: "ui-state-hover",
    hoverClass: "ui-state-active",
    drop: function( event, ui ) {

        var targetElem = $(this).attr("id");

        $( this )
            .addClass( "ui-state-highlight" )
            .find( "p" )
            .html( "Dropped! inside " + targetElem );

            alert(targetElem);

        var container = $( this ).find( "ul.dropped-items" ).css({border:"blue solid 1px"});

        container.append(ui.draggable.clone());

        ui.draggable.remove();

    }
});

The dropped item should be appended into this element,

<ul class="dropped-items">
</ul>

But it just not happening. What have I missed and how can I make it work?

jsfiddle test page.


回答1:


You could removing the absolute position styling on the element:

Javascript

...
container.append(ui.draggable.clone().css({position: 'relative', left: 0, top: 0, width: 'auto', height: 'auto'}));
...

Demo

Or, add the styling in to do the same:

CSS

.dropped-items li {
    position: relative !important;
    top: 0 !important;
    left: 0 !important;
    width: auto !important;
    height: auto !important;
}

Demo



来源:https://stackoverflow.com/questions/13870942/jquery-sortable-and-droppable-cannot-append-the-drop-item

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!