我正在尝试使用packery编写一个水平滚动,可拖动/可排序的列表。
基本上我想制作这个代码笔的水平版本:http://codepen.io/desandro/pen/cbhDG
我尝试修改它,并且可以获得带有滚动条的水平列表没有问题,问题是一旦我应用包装,它就想垂直包装单元格并且似乎消除了溢出,我找不到控制包装容器大小的方法
这是我到目前为止的尝试:http://codepen.io/anon/pen/dPYXJG
哈姆尔:
%div.all-slides
%div.slides
- (1..12).each do |i|
%div.slide
%div#cloned-slides.cloned-slides
.css:
html, body {
height: 100%;
width:100%;
overflow: hidden;
background: #8D939D;
margin: 0;
}
.all-slides {
width: 100%;
height: 120px;
white-space: nowrap;
overflow-y: hidden;
overflow-x: scroll;
-webkit-overflow-scrolling: touch;
padding: 1rem;
background-color: #ccc;
}
.slide {
display:inline-block;
width: 100px;
height: 60px;
background: green;
position: relative;
margin:3px;
z-index: 5;
user-select: none;
}
JavaScript:
docReady( function() {
var slidesElem = document.querySelector('.slides');
var slideSize = getSize( document.querySelector('.slide') );
var pckry = new Packery( slidesElem, {
columnWidth : slideSize.outerWidth,
rowHeight: slideSize.outerHeight
});
// get item elements
var itemElems = pckry.getItemElements();
// for each item...
for ( var i=0, len = itemElems.length; i < len; i++ ) {
var elem = itemElems[i];
// make element draggable with Draggabilly
var draggie = new Draggabilly( elem, {
axis: 'x'
});
// bind Draggabilly events to Packery
pckry.bindDraggabillyEvents( draggie );
}
// re-sort DOM after item is positioned
pckry.on( 'dragItemPositioned', function( _pckry, draggedItem ) {
var index = pckry.items.indexOf( draggedItem );
var nextItem = pckry.items[ index + 1 ];
if ( nextItem ) {
slidesElem.insertBefore( draggedItem.element, nextItem.element );
} else {
slidesElem.appendChild( draggedItem.element );
}
});
});
任何帮助将不胜感激。干杯。
当然! http://codepen.io/desandro/pen/ByoQwN
我将包装选项行高度:slldeSize.outerWidth更改为列宽度:slideSize.outerHeight,并将Draggabilly选项轴:"y"更改为轴:"x"。其他一切都由 CSS 处理。
var slidesElem = document.querySelector('.slides');
var slideSize = getSize( document.querySelector('.slide') );
var pckry = new Packery( slidesElem, {
rowHeight: slideSize.outerHeight
});
// get item elements
var itemElems = pckry.getItemElements();
// for each item...
for ( var i=0, len = itemElems.length; i < len; i++ ) {
var elem = itemElems[i];
// make element draggable with Draggabilly
var draggie = new Draggabilly( elem, {
axis: 'y'
});
// bind Draggabilly events to Packery
pckry.bindDraggabillyEvents( draggie );
}