|
| 1 | +# jquery.wRECkeR |
| 2 | +> wRECkeR: Responsive Equal-Height Columns and Rows |
| 3 | +
|
| 4 | + |
| 5 | +## THIS LIBRARY IS OBSOLETE! |
| 6 | +Unless you're supporting _extremely_ old browsers, you should instead be using [flexbox](https://developer.mozilla.org/docs/Web/CSS/CSS_flexible_box_layout/Basic_concepts_of_flexbox). |
| 7 | + |
| 8 | +--- |
| 9 | + |
| 10 | +Wrecker is a dynamic layout plugin for jQuery that achieves equal-height rows in a grid layout. Similar to a `float` layout in that excess "cells" are moved to the following "row". However, unlike, in that columns line up vertically and the cells of each row are equal in height based on their contents, just like a `<table>`. No static heights required. |
| 11 | + |
| 12 | +Check out the [simple demo](https://stevenvachon.github.io/jquery.wrecker/simple.html) and the [advanced demo](https://stevenvachon.github.io/jquery.wrecker/advanced.html). Note: they have not been tested with Internet Explorer™ 7 and below. |
| 13 | + |
| 14 | + |
| 15 | +## Usage |
| 16 | + |
| 17 | +Start with a `float` layout. |
| 18 | + |
| 19 | +```html |
| 20 | +<div id="container"> |
| 21 | + <div class="item">…</div> |
| 22 | + <div class="item">…</div> |
| 23 | + <div class="item">…</div> |
| 24 | + <div class="item">…</div> |
| 25 | + … |
| 26 | +</div> |
| 27 | +``` |
| 28 | + |
| 29 | +```css |
| 30 | +.item { |
| 31 | + float: left; |
| 32 | + width: 25%; |
| 33 | +} |
| 34 | +``` |
| 35 | + |
| 36 | +Add jQuery and the Wrecker script. |
| 37 | + |
| 38 | +```html |
| 39 | +<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js"></script> |
| 40 | +<script src="/path/to/jquery.wrecker.min.js"></script> |
| 41 | +``` |
| 42 | + |
| 43 | +It is recommended that you specify itemSelector, maxColumns and responsiveColumns. |
| 44 | + |
| 45 | +```js |
| 46 | +$(function() { |
| 47 | + $('#container').wrecker({ |
| 48 | + // options |
| 49 | + itemSelector : '.item', |
| 50 | + maxColumns : 4, |
| 51 | + responsiveColumns : [ |
| 52 | + // windowMaxWidth : columns |
| 53 | + // windowMaxWidth order and values should match those in your responsive CSS |
| 54 | + { 1024 : 3 }, |
| 55 | + { 800 : 2 }, |
| 56 | + { 40 : 1 } |
| 57 | + ] |
| 58 | + }); |
| 59 | +}); |
| 60 | +``` |
| 61 | + |
| 62 | + |
| 63 | +## How it works |
| 64 | + |
| 65 | +The previous layout is converted into a `display:table` layout where the responsive column span is handled by dynamically adding and removing `<div>` "rows" around the "cells". Equal-height rows are handled automatically by the browser (very fast). Responsive column widths are handled with standard CSS. |
| 66 | + |
| 67 | +Single-column layouts and those with JavaScript disabled will be served the `float` layout. |
| 68 | + |
| 69 | + |
| 70 | +## Important Notes |
| 71 | + |
| 72 | +Due to the nature of `display:table` layouts, there are a few possible issues: |
| 73 | + |
| 74 | +1. There is currently no known `colspan`/`rowspan` equivalent in CSS |
| 75 | +2. `max-width` is ignored on the main element (`#container` in the above example) |
| 76 | +3. `margin` values will be ignored on the cells. You will need to do something like [Inside-Only CSS Table border-spacing](https://svachon.com/blog/inside-only-css-table-border-spacing/). Check out the [advanced demo](https://stevenvachon.github.io/jquery.wrecker/advanced.html). |
| 77 | + |
| 78 | + |
| 79 | +## Other Functions |
| 80 | + |
| 81 | +To recalculate the grid. Useful for adding new items. |
| 82 | +```js |
| 83 | +.wrecker('reload'); |
| 84 | +``` |
| 85 | + |
| 86 | +To remove Wrecker functionality completely and return the element back to its pre-initialized state. |
| 87 | +```js |
| 88 | +.wrecker('destroy'); |
| 89 | +``` |
0 commit comments