Logic behind drag and drop

喜你入骨 提交于 2019-12-03 09:32:29

I believe jquery gives you a way to grab their order based on id?

The way I've been doing it is every time an action occurs, grab the current order, send it back to my app via ajax. Then my app just parses out the ids from what it was given and updates every item's order value.

http://jqueryui.com/demos/sortable/

    $("#col1").sortable({
        placeholder: "top",
        forcePlaceholderSize: true,
        revert: true, 
        update: function() { 
                $.ajax({
                     type: "GET",
                     url: "/request.php",
                     data: "data="+$(this).sortable("toArray")+"",
                     success: function(msg){ }
                        });         
             }
    });

toArray is a sequence of your divs ids

Unless you are doing this for your own education, I would suggest that you use jQueryUI.

It has drag-and-drop functionality, amongst other things, that would probably help you with the nitty-gritty of DaD, leaving you to implement the parts that are specific to your problem.

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