2015-04-07 72 views
2

我试图在此页面上实现“多”示例... http://rubaxa.github.io/Sortable/。我觉得自己已经“重新创建”了https://github.com/RubaXa/Sortable上提出的结构和适当的选项,但我正在努力让它按照我的意愿运作。可排序的Javascript与rubaxa

的什么,我试图做的是这里的简化版本... https://jsfiddle.net/uqcqufo8/

HTML ...

<div id="multi"> 

<div><div data-force="5" class="layer title title_xl">Multi</div></div> 

    <div class="layer tile" data-force="30" style="width:100px; height:100px; background:grey; margin:5px; display:inline-block; color:red;"> 

    <div class="tile__name">Group A</div> 
     <div class="tile__list"> 
      <div style="background:red; width:10px; height:10px; margin:2px; display:inline-block;"></div> 
      <div style="background:blue; width:10px; height:10px; margin:2px; display:inline-block;"></div> 
      <div style="background:green; width:10px; height:10px; margin:2px; display:inline-block;"></div> 
     </div> 
    </div> 

    <div class="layer tile" data-force="30" style="width:100px; height:100px; background:grey; margin:5px; display:inline-block; color:red;"> 
    <div class="tile__name">Group c</div> 
    <div class="tile__list"> 
     <div style="background:red; width:10px; height:10px; margin:2px; display:inline-block;"></div> 
     <div style="background:blue; width:10px; height:10px; margin:2px; display:inline-block;"></div> 
     <div style="background:green; width:10px; height:10px; margin:2px; display:inline-block;"></div> 
    </div> 
    </div> 

    <div class="layer tile" data-force="30" style="width:100px; height:100px; background:grey; margin:5px; display:inline-block; color:red;"> 
    <div class="tile__name">Group b</div> 
    <div class="tile__list"> 
     <div style="background:red; width:10px; height:10px; margin:2px; display:inline-block;"></div> 
     <div style="background:blue; width:10px; height:10px; margin:2px; display:inline-block;"></div> 
     <div style="background:green; width:10px; height:10px; margin:2px; display:inline-block;"></div> 
    </div> 
    </div> 

</div> 

的JavaScript ...

var el = document.getElementById('multi'); 
      var sortable = Sortable.create(el, { 
       animation: 150, 
       handle: ".tile__name", 
       draggable: ".tile" 
}); 

基本上,大的灰色方块应该可以排序(因为它们是),但彩色方块也应该是可排序的 - 它们应该可以在各自的盒子中排序,并且它们应该可以从一个灰色框到另一个。我无法看到我错过了什么。谢谢。

回答

2

我编辑了你的javascript到下面,它适用于我。我遵循可排序页面上的示例,因此它可能是首选方法:

var el = document.getElementById('multi'); 
var sortable = Sortable.create(el, { 
    animation: 150, 
    handle: ".tile__name", 
    draggable: ".tile" 
}); 
[].forEach.call(document.getElementById('multi').getElementsByClassName('tile__list'), function (el){ 
    Sortable.create(el, { 
     group: 'blocks', 
     animation: 150 
    }); 
});