jQuery-UI Draggable and Sortable

杀马特。学长 韩版系。学妹 提交于 2020-01-01 15:40:57

问题


So I've been working with this example: http://jqueryui.com/demos/draggable/#sortable and I've accomplished it on my product. However I want to make two significant changes.

  1. I don't want the second list(toList in my example) to be sortable on it's own. I only want it to accept items from the first list(fromList in my example).

  2. When a user drags an item from the first list(fromList) and drops it into the second list(toList) I want that item to be forced to the bottom.

Suggestions? Here is a working fiddle of what I have so far. http://jsfiddle.net/CrtFD/


回答1:


Try using a droppable for your toList:

EDIT: Per comments below:

http://jsfiddle.net/abzYK/

jQuery(document).ready(function(){
    jQuery("#fromList li").draggable('destroy').draggable({
        connectToSortable: "#toList",
        revert: "invalid",
        containment: '#equipCont',
        helper: function(e, ui) {
            return jQuery(this).clone().css('width', jQuery(this).width());
        }
    });
    jQuery("#toList").droppable('destroy').droppable({
        drop: function(e, ui) {
            var dragClone = jQuery(ui.draggable).clone();
            jQuery("#toList").append(dragClone);
        }
    });
    jQuery("ul, li").disableSelection();
});
​



回答2:


You want your toList to be Droppable, not Sortable. This example seems to describe what you are trying to accomplish: http://jqueryui.com/demos/droppable/#shopping-cart



来源:https://stackoverflow.com/questions/7828495/jquery-ui-draggable-and-sortable

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