简体   繁体   English

垂直排列父母,水平排列孩子

[英]sort parents vertically and child horizontally

sortable on part works fine - single are sorted horizontally. 可排序的part效果很好- single被水平排序。

Why parent is not sortable - to sort part vertically ? 为什么parent无法排序-垂直排序part

  $('.parent').sortable({ items: ".part", containment: "parent", tolerance: "pointer", axis: "y", }); $('.part').sortable({ containment: "parent", tolerance: "pointer", axis: "x", }); 
 .parent{ background:silver; position:fixed; width:90%; left:5%; height:50px; overflow-y:scroll; } .part{ background:lightgreen; margin:5px; display:grid; grid-template-columns:50% 50%; } .single{ background:gold; cursor:cell; } 
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script> <div class='parent'> <div class='part'> <div class='single'>lorem1</div> <div class='single'>ipsum1</div> </div> <div class='part'> <div class='single'>lorem2</div> <div class='single'>ipsum2</div> </div> </div> 

The primary issue is that there is no place to click on $(".part") without clicking on $(".single") . 主要问题在于,没有地方可以单击$(".part")而不单击$(".single") The target of the sort event is then the part and not the parent. 然后,排序事件的目标是零件而不是父项。

I would advise either a handle, or some amount of padding. 我建议您使用一个手柄或一些填充物。

 $(function() { $('.parent').sortable({ items: "> .part", containment: "parent", tolerance: "pointer", axis: "y", }); $('.part').sortable({ containment: "parent", items: "> .single", tolerance: "pointer", axis: "x", }); }); 
 .parent { background: silver; position: fixed; width: 90%; left: 5%; height: 50px; overflow-y: scroll; } .part { background: lightgreen; margin: 5px; padding-left: 16px; display: grid; grid-template-columns: 50% 50%; } .single { background: gold; cursor: cell; } 
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script> <div class='parent'> <div class='part'> <div class='single'>lorem1</div> <div class='single'>ipsum1</div> </div> <div class='part'> <div class='single'>lorem2</div> <div class='single'>ipsum2</div> </div> </div> 

By adding some padding, 16px worth on the left, I now have a defined space I can grab a Part without grabbing a single, and I can sort it as expected. 通过在左侧添加一些填充(值16px),我现在有了一个定义的空间,可以抓住部件而不必抓住单个部件,并且可以按预期对它进行排序。 items may not be needed, but it does clarify things when reviewing the code. 可能不需要这些items ,但是在检查代码时确实可以使事情澄清。

Hope that helps. 希望能有所帮助。

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

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