-
Notifications
You must be signed in to change notification settings - Fork 311
Getting Started
Shapeshift requires the latest version of jQuery (1.9.1 minimum), and drag and drop feature (enabled by default) requires jQuery UI Draggable/Droppable libraries. It also requires jQuery Touch Punch to work on touch devices.
Shapeshift arranges child elements by absolutely positioning them in their parent container which must be set to "position: relative". The container does not have to be a div and can be substituted for any element that can have child elements, such as an unordered list. The container also must have a width specified.
<div class="container"></div>
.container {
position: relative;
width: 100%;
}
By default all child elements within the parent container will be Shapeshifted. Just make sure that they are set to "position: absolute" in your CSS file. The children also must have a height/width specified.
<div class="container">
<div>Child Element 1</div>
<div>Child Element 2</div>
<div>Child Element 3</div>
<div>Child Element 4</div>
...
</div>
.container {
position: relative;
width: 100%;
}
.container div {
height: 50px;
position: absolute;
width: 50px;
}
Shapeshift relies on a column grid system, this means that every time Shapeshift is initialized on a container it will determine the column width based on the width of the first child in that container. If no column width is specified on a child element then Shapeshift will assume it will use it to set the single column width for the grid.
To make a child element multiwidth, simply add the data attribute "data-ss-colspan=X", where X is the amount of columns it should span. Shapeshift does not automatically set their width though so the childs width must already be set to the correct width. The calculated width must be set to: "single column width * columns to span + the gutter space in between".
For example, assuming the default gutter value of 10px, multiwidth elements can be created as such:
<div class="container">
<div>Spans 1 Column</div>
<div data-ss-colspan="2">Spans 2 Columns</div>
<div data-ss-colspan="3">Spans 3 Columns</div>
<div data-ss-colspan="4">Spans 4 Columns</div>
...
</div>
.container {
position: relative;
width: 100%;
}
.container div {
height: 120px;
position: absolute;
width: 80px;
}
.container div[data-ss-colspan="2"] { width: 170px; }
.container div[data-ss-colspan="3"] { width: 260px; }
.container div[data-ss-colspan="4"] { width: 350px; }
Now that we have our setup complete, simply call .shapeshift() on the parent element. It will, by default, select all the children in the parent element to be rearranged.
$('.container').shapeshift();