jquery - 将项目从一个可排序的 jqueryui 获取到另一个时禁用项目移动的动画

标签 jquery user-interface jquery-ui-sortable

我希望在每个可排序项中都具有可排序功能。在两个可排序之间,我想将可拖动项目移动到占位符上,即可放置项目。我希望它看起来好像该元素掉落到可掉落物上。现在,它应该可以在另一个可排序中进行排序。因此,我已将所有可排序连接起来,并且在放置在占位符上时,我删除了该占位符并添加了此拖动的项目。

但是,将项目悬停在任何其他可排序对象上时,它会显示项目移动的动画。我不想要那个动画,因为理想情况下应该没有额外的可用空间。该元素只能放在可放置的元素上。

这可能吗?我该怎么做?

谢谢

我创建的 fiddle 的链接是:http://jsfiddle.net/ZTu24/

代码如下:

var rearrange = function (rowSelector) {

   var counter = 1;
   $("#" + rowSelector).children(".innerDiv").each(function () {
       $(this).children(":first").html(this.id + " " + counter++);
   });
}

$(function () {


   rearrange("row1");
   rearrange("row2");
   $(".innerDivPlaceholder").droppable({

       activeClass: "droppableHighlight",
       drop: function (event, ui) {

           alert("Dropped !!");
           var sourceRow = ui.helper.context.attributes[1].value; // to get value of token id
           var destinationRow = $(this).context.attributes[1].value; // to get value of token id
           sourceRow1 = new String(sourceRow);
           destinationRow1 = new String(destinationRow);

           //console.log(ui.helper.context);
           alert("Source Row = " + sourceRow1);
           alert("Destination Row = " + destinationRow1);
           if (sourceRow == destinationRow) {
               alert("Source equals destination");
               dropCancelled = true;
               return false;
           } else {
               $(this).remove();
           }
       }
   });
   $(".sortable").sortable({


       connectWith: ".sortable",
       revert: true,
       cancel: ".ui-state-disabled",
       //items : ".innerDiv:not(.innerDivPlaceholder)" ,


       stop: function (event, ui) {

           //$(".sortable").sortable( "enable" );
           var targetList = $(this);

           rearrange(targetList.context.id);

       }
   });
   $(".sortable").disableSelection();

   $(".sortable").on("sortreceive", function (event, ui) {


       var sourceList = ui.sender;
       var targetList = $(this);
       alert("In sortreceive ");
       //alert("Source id = " + sourceList.context.id);
       //alert("Target id = " + targetList.context.id);
       if ($(this).sortable('toArray').length > 3) {
           $(ui.sender).sortable('cancel');
       } else {

           var placeHolderDiv = document.createElement('div');

           placeHolderDiv.setAttribute("id", "placeholder100");
           placeHolderDiv.setAttribute("tokenid", sourceList.context.id);
           placeHolderDiv.setAttribute("class", "innerDivPlaceholder innerDiv ui-state-default ui-state-disabled floatLeftClass column3");


           //var innerPara1 = document.createElement('p');
           //innerPara1.textContent = "placeholder";
           //placeHolderDiv.appendChild(innerPara1);
           $(placeHolderDiv).droppable({

               activeClass: "droppableHighlight",
               drop: function (event, ui) {

                   alert("Dropped !!");
                   var sourceRow = ui.helper.context.attributes[1].value;
                   var destinationRow = $(this).context.attributes[1].value;
                   sourceRow1 = new String(sourceRow);
                   destinationRow1 = new String(destinationRow);


                   alert("Source Row = " + sourceRow1);
                   alert("Destination Row = " + destinationRow1);
                   if (sourceRow == destinationRow) {
                       alert("Source equals destination");
                       dropCancelled = true;
                       return false;
                   } else {
                       $(this).remove();
                   }
               }
           });

           $(placeHolderDiv).appendTo("#" + sourceList.context.id).sortable({

               connectWith: ".dottedDiv",
               revert: true,
               cancel: ".ui-state-disabled",
               //items : ".innerDiv:not(.innerDivPlaceholder)",
               stop: function (event, ui) {

                   //$(".sortable").sortable( "enable" );
                   var targetList = $(this);


                   rearrange(targetList.context.id);

               }
           }).disableSelection();


           rearrange(sourceList.context.id);
           rearrange(targetList.context.id);
           alert("Received !!");
       }
   });

   $(".dropDown").DropDown({


       menus: [{
           label: "Increase column span",
           action: "new",
           icon: 'print-icon'
       }, {
           label: "Decrease column span",
           action: "save",
           icon: 'print-icon' // classes: placing appropriate images at right place
       }],
       maxWidth: 100,
       groupLabel: 'File Hello',
       groupIcon: 'tick-icon',
       orientation: 'horizontal'
   });

});

最佳答案

我遇到了和你一样的问题。我将占位符设置为虚拟 div 标签以禁用移动动画。

$("#dragger").sortable({
    connectWith: "#dropper",
    placeholder: "<div></div>"
});

$("#dropper").sortable();

关于jquery - 将项目从一个可排序的 jqueryui 获取到另一个时禁用项目移动的动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21324968/

相关文章:

javascript - 使用一个命令放置一个按钮及其 div

javascript - 无法调试卡在 firefox 扩展中的 $.post

javascript - 用正则表达式替换选择索引属性

javascript - 渐变不适用于 IE

javascript - jquery 移动圆形导航后退按钮

user-interface - 企业产品的功能区 UI 用户指南或示例

user-interface - 用户界面上的 "ID"或 "Id"

winapi - 尽管正确设置了 szTip,但通知图标工具提示并未显示

php - Jquery 可排序列表不会序列化,为什么?

javascript - jQuery UI 可排序多元素目标