简体   繁体   English

jQuery ui-删除可拖动元素之间的空间

[英]jquery ui - remove space between draggable elements

Please find this fiddle . 请找到这个小提琴 Here sorting of elements works fine when I drop element back to "Events" area. 当我将元素放回“事件”区域时,这里的元素排序工作正常。 But the problem is when I drag an element from "Events" area, the space occupied by that element won't remove. 但是问题是,当我从“事件”区域拖动元素时,该元素占用的空间不会删除。 I want to remove that space or sorting when element is dragged from "Events" area. 我想从元素“事件”区域中拖动元素时删除该空间或排序。 The condition is I don't want to use sortable of jquery ui . 条件是我不想使用jquery ui sortable I don't want sorting in "Drop" area. 我不想在“拖放”区域中排序。

As shown in jsfiddle that there is no sorting on "Drop" area but there is a sorting on "Events" area. 如jsfiddle所示,“ Drop”区域没有排序,但“ Events”区域却有排序。 But the sorting on "Events" works only when an element is dropped inside it. 但是,只有在将元素放入其中时,“事件”的排序才有效。

For example, if I drag "Event 2" and drop it on "Drop" area, the space between "Event 1" and "Event 3" remains. 例如,如果我将“事件2”拖放到“拖放”区域,则“事件1”和“事件3”之间的空间仍然存在。 I want to remove that space. 我要删除该空间。 so the order will be Event1, Event3 and when I drop "Event 2" back to "Events", the order will be Event1, Event2, Event3. 因此顺序为Event1,Event3,当我将“ Event 2”放回“ Events”时,顺序为Event1,Event2,Event3。

$("li.ui-draggable").draggable({
     revert: "true",
 });

 $("#eventlist").droppable({
     accept: ".ui-draggable",
     tolerance: 'touch',
     drop: function (event, ui) {
         // event sorting
         console.log(':::inside drop of eventlist:::');
         var $item = ui.draggable;
         $(this).append($item);
         $item.css({
             top: 0,
             left: 0
         });

         var seen = [];

         $(this).find('.ui-draggable').each(function (index, item) {
             seen.push($(item).attr('id'));
         });
         console.log(':::seen array:::', seen);
         seen.sort();
         for (var i = 0; i < seen.length; i++) {
             $(this).append($(this).find('#' + seen[i]));
         }
     }
 });

How do I remove the space in between the draggable elements or sort elements while dragging ????? 拖动时如何删除可拖动元素或排序元素之间的空间?

make your #timeline droppable and remove sorting something like this JSFiddle Additionally, you can implement "on hover" 使您的#timeline可放置,并删除诸如此类的排序JSFiddle此外,您可以实现“悬停”

$('#timeline').droppable({
          accept: ".ui-draggable",      
          tolerance: 'touch',
          drop:function(event, ui){
                // event sorting
                console.log(':::inside drop of eventlist:::');
                var $item=ui.draggable;
                $(this).append($item);
                $item.css({top:0,left:0});

                var seen=[]; 

                $(this).find('.ui-draggable').each(function(index,item)
                {
                    seen.push($(item).attr('id'));
                });
                console.log(':::seen array:::',seen);    
                //seen.sort();
                for(var i = 0 ; i < seen.length ; i++){                    
                    $(this).append($(this).find('#'+seen[i]));
                }
          }
      });

Just for a Hint , you have to change CSS by jquery in following event :- 仅出于提示,您必须在以下事件中通过jquery更改CSS:

$("li.ui-draggable").draggable({                              
    revert: "true",
    stop: function( event, ui ) {
     $(this).appendTo('ul');
    // Change in CSS code
    }
 });

This event is fired when the item is dropped in the below DIV. 将项目放在下面的DIV中时将触发此事件。

Check this one if it is useful to you Fiddle 检查这一个,如果它是对你有用小提琴

$("#origin").sortable({
    connectWith: "#drop"
});

$("#drop").sortable({
    connectWith: "#origin"
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM