Vertical grids
In vertical grids items are positioned inside fixed width container:
Initializing vertical grid
var grid = document.body.querySelectorAll(".grid-selector");
// Setting {grid: "vertical"} will be used by default
var asyncGrid = new Gridifier(grid);
Horizontal grids
In horizontal grids items are positioned inside fixed height container:
Initializing horizontal grid
var grid = document.body.querySelectorAll(".grid-selector");
var asyncGrid = new Gridifier(grid, {grid: "horizontal"});
Grid overflows
How Gridifier is affecting grid overflow settings?
- Gridifier is not changing grid overflow settings.
- With responsive web-sites and vertical grids you should add
overflow-x: "hidden" rule to body tag to avoid horizontal scrollbars.
- Unfortunately, you can't set overflow-x: "hidden" together with overflow-y: "visible" rules
directly on the grid element. Browsers will automatically switch overflow-y to auto value.
- Setting grid overflow to "hidden" will make some animations(like rotates) look
'cut-off' in some cases, so we can't set it by default.
On this site we are setting it on body tag like this:
Hiding horizontal scrollbar on responsive sites
/* We think that is the best solution, because with responsive sites
horizontal scrollbar is not really required */
body {
position: relative;
overflow-x: hidden;
}
Centering grids
How to center vertical grid relative to wrapper?
CSS
.grid {
margin: 0 auto;
/* Max-width can be any required px/% value */
max-width: 90%;
}
How to center horizontal grid relative to wrapper?
HTML
/* We can't use margins here, so we need emulate table vertical-centering through CSS */
<div class="gridWrapper">
<div class="gridAlignerWrapper">
<div class="gridAligner">
<div class="grid">
</div>
</div>
</div>
</div>
CSS
.gridWrapper {
width: 100%;
height: 500px;
overflow-x: scroll;
overflow-y: hidden;
}
.gridAlignerWrapper {
display: table;
width: 100%;
height: 100%;
}
.gridAligner {
width: 100%;
height: 100%;
display: table-cell;
vertical-align: middle;
}
.grid {
/* Specify required height here */
height: 200px;
}
Grid spacers
How to add additional space around grid?
As we mentioned earlier in usage chapter, Gridifier is ignoring
padding on grid due to the item resolving bugs in different browsers.
You can set margins per grid items, however if you want add additional
spacers around grid you should wrap grid with additional element with
paddings:
Adding spacers with wrapper:
Html
<div class="spacer">
<div class="grid">
</div>
</div>
Css
.spacer {
width: 100%;
min-height: 200px;
box-sizing: border-box;
padding: 20px;
}
.spacer .grid {
width: 100%;
}
Alternatively, you can use margins + calcs:
Adding spacers with margins/calcs:
Html
<div class="grid">
</div>
Css
.grid {
width: calc(100% - 40px);
margin: 20px;
min-height: 300px;
}
Grid settings
What grid settings can be passed to constructor or changed later?
gridResize
sets grid sizes update type after item inserts/disconnects and grid resizes
default = "fit"
- fit
- grid height/width is always set up according to max grid item Y2/X2.(used by default)
- expand
- grid width/height is updated only to higher values.
- disabled
- grid height/width updates are disabled.
gridResizeDelay
sets ms timeout, after which grid sizes updates will be applied
default = 100
- Gridifier is applying grid sizes changes after specified ms timeout.
- If multiple items are inserted/disconnected, this timeout will be rescheduled.
- It is required because it is too expensive to update grid sizes after each
insert/disconnect on touch devices.
- On small grids you can set this
value to 20 or 0, if delay between inserts and grid sizes changes is noticeable.
vpResizeDelay
sets ms timeout, after which Gridifier will reposition all grid items on viewport resizes
default = null
queueSize
sets size of reposition queue
default = 12
- With this setting you can control items count in one batch, processed
by reposition queue.
- This can be especially useful with no intersections mode, when
custom aligns(center, right, bottom) are used.
queueDelay
sets ms timeout between reposition queue launches
default = 25
Grid helpers
What additional grid helpers are available?
reposition()
reposition = function()
reposition all connected to grid items
gridWidth()
gridWidth = function()
returns current grid width
gridHeight()
gridHeight = function()
returns current grid height
grid()
grid = function()
returns grid
Events
What events are emitted during grid interaction operations?
onRepositionEnd event
event, which is emitted after all grid item reposition finish
onGridResize event
event, which is emitted after almost all grid operations
next: Insert types
prev: Settings