Skip to content

Commit

Permalink
Added setGridHeight function.
Browse files Browse the repository at this point in the history
  • Loading branch information
zaxovaiko committed Jun 30, 2018
1 parent dfd83c4 commit 07860dc
Show file tree
Hide file tree
Showing 6 changed files with 924 additions and 844 deletions.
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,21 @@
### How to use?

- You can download it with [stratum.js CDN](https://cdn.rawgit.com/zaxoavoki/stratum.js/31373231/dist/stratum.min.js);
- Use npm catalog;
- Use npm catalog *(in future)*;

----------

You can create a grid using `stratum()` function. It gets object as
parameter with two options:

#### `padding:`

- Set padding gaps between grid items. You can put *number* or *string* in such format: `padding: '15px 10px 20px 30px'`, which means
that you want to set padding-top with **15px**, padding-bottom with **20px** and etc.

#### `columns:`

- Set an amount of columns in grid. Can be only a *number*.

### Future updates

Expand Down
10 changes: 7 additions & 3 deletions demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<body>

<div class="container">
<div data-grid="3">
<div id="grid">
<div class="card">
<div class="card-body">
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Est, et eveniet! Ab alias beatae delectus
Expand Down Expand Up @@ -101,15 +101,19 @@
</div>
</div>
</div>

Lorem ipsum dolor sit amet, consectetur adipisicing elit. Alias, asperiores delectus dolore dolorum illo illum
labore laboriosam nemo neque nulla provident quia quibusdam, quos reiciendis, reprehenderit sequi sit sunt
voluptates!
</div>

<!-- Include jQuery first and stratum.js -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="../dist/stratum.min.js"></script>
<script>
$('[data-grid]').stratum({
$('#grid').stratum({
padding: 5,
columns: 2
columns: 3
});
</script>

Expand Down
33 changes: 32 additions & 1 deletion dist/stratum.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@
});

//
// Main cycle: there we will check current coordinates
// Main cycle will check current coordinates
//
grid.children().each(function (i, obj) {

var gridItem = $(obj);
Expand All @@ -148,8 +149,35 @@
top: getTopPosition(gridItem, i)
});
});

setGridHeight(heights);
}

//
// Count grid height value
//
function setGridHeight(array) {
var maxSectionHeight = 0,
sectionHeight = void 0;
for (var col = 0; col < columns; col++) {
sectionHeight = 0;
for (var i = col; i < array.length; i += columns) {
sectionHeight += array[i];
}

if (maxSectionHeight < sectionHeight) {
maxSectionHeight = sectionHeight;
}
}

grid.css({
'height': maxSectionHeight
});
}

//
// Rewrite top position value while resizing
//
function resize() {
heights = [];
top = 0;
Expand All @@ -164,10 +192,13 @@
top: getTopPosition(gridItem, i)
});
});

setGridHeight(heights);
}

//
// Get current top position value
//
function getTopPosition(obj, index) {
if (heights[index - columns] === undefined) {
top = 0;
Expand Down
2 changes: 1 addition & 1 deletion dist/stratum.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 07860dc

Please sign in to comment.