Skip to content

Commit 3474380

Browse files
authored
Merge pull request #18 from e-oj/master
update
2 parents 809039c + 02f6f7d commit 3474380

File tree

8 files changed

+68
-23
lines changed

8 files changed

+68
-23
lines changed

README.md

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ Creating a dynamic grid layout has never been easier. With Magic Grid, all you h
1212

1313
<img src="http://drive.google.com/uc?export=view&id=172ESPZDwQIf7vLMelun-_4RaWD_-j94-" alt="demo" width="850"></img>
1414

15-
#### [@imlinus](https://github.com/imlinus) has created a Vue.js port of the library. You can check it out [here](https://github.com/imlinus/Vue-Magic-Grid).
16-
1715
### Why not CSS Grid?
1816

1917
This question is addressed in <b>[the article](https://codeburst.io/magic-grid-f8e2221e7cef)</b>:
@@ -24,6 +22,13 @@ Check out <b>[CSS Grid AMA's issue #19](https://github.com/rachelandrew/cssgrid-
2422

2523
> That's not something grid is designed for. Grid is two dimensional so you are always working in both rows and columns at the same time. You can't use grid to do a "masonry" style layout like that. You could place items in that way if you had a lot of rows and managed how many each spanned, but you can't use auto-placement to get that kind of layout.
2624
25+
### Ports
26+
27+
| Repo | Author |
28+
|:--------|:-------|
29+
| [Vue-Magic-Grid](https://github.com/imlinus/Vue-Magic-Grid) | [@imlinus](https://github.com/imlinus) |
30+
| [Magic-Grid-React](https://github.com/IniZio/Magic-Grid-React) | [@IniZio](https://github.com/IniZio) |
31+
2732
### Getting Started
2833
#### Step 1
2934

@@ -109,9 +114,10 @@ let magicGrid = new MagicGrid({
109114
static: false, // Required for static content. Default: false.
110115
items: 30, // Required for dynamic content. Initial number of items in the container.
111116
gutter: 30, // Optional. Space between items. Default: 25(px).
112-
maxColumns: 5, // Maximum number of columns. Default: Infinite.
113-
useMin: true, // Prioritize shorter columns when placing items in the grid. Default: false.
114-
animate: true, // Animate item positioning. Default: false.
117+
maxColumns: 5, // Optional. Maximum number of columns. Default: Infinite.
118+
useMin: true, // Optional. Prioritize shorter columns when positioning items. Default: false.
119+
useTransform: true // Optional. Position items using CSS transform. Default: True.
120+
animate: true, // Optional. Animate item positioning. Default: false.
115121
});
116122
```
117123

dist/magic-grid.cjs.js

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ var checkParams = function (config) {
1515
throw new Error("No config object has been provided.");
1616
}
1717

18+
if(typeof config.useTransform !== "boolean"){
19+
config.useTransform = true;
20+
}
21+
1822
if (!config.container) { error("container"); }
1923
if (!config.items && !config.static) { error("items or static"); }
2024
};
@@ -75,6 +79,7 @@ var MagicGrid = function MagicGrid (config) {
7579
this.gutter = config.gutter || 25;
7680
this.maxColumns = config.maxColumns || false;
7781
this.useMin = config.useMin || false;
82+
this.useTransform = config.useTransform;
7883
this.animate = config.animate || false;
7984
this.started = false;
8085

@@ -92,10 +97,12 @@ MagicGrid.prototype.init = function init () {
9297
this.container.style.position = "relative";
9398

9499
for (var i = 0; i < this.items.length; i++) {
95-
this.items[i].style.position = "absolute";
100+
var style = this.items[i].style;
101+
102+
style.position = "absolute";
96103

97104
if (this.animate) {
98-
this.items[i].style.transition = "transform 0.2s ease";
105+
style.transition = (this.useTransform ? "transform" : "top, left") + " 0.2s ease";
99106
}
100107
}
101108

@@ -174,10 +181,16 @@ MagicGrid.prototype.positionItems = function positionItems () {
174181
var col = this.nextCol(cols, i);
175182
var item = this.items[i];
176183
var topGutter = col.height ? this.gutter : 0;
177-
var left = col.index * colWidth + wSpace;
178-
var top = col.height + topGutter;
184+
var left = col.index * colWidth + wSpace + "px";
185+
var top = col.height + topGutter + "px";
179186

180-
item.style.transform = "translate(" + left + "px, " + top + "px)";
187+
if(this.useTransform){
188+
item.style.transform = "translate(" + left + ", " + top + ")";
189+
}
190+
else{
191+
item.style.top = top;
192+
item.style.left = left;
193+
}
181194

182195
col.height += item.getBoundingClientRect().height + topGutter;
183196

dist/magic-grid.esm.js

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ var checkParams = function (config) {
1313
throw new Error("No config object has been provided.");
1414
}
1515

16+
if(typeof config.useTransform !== "boolean"){
17+
config.useTransform = true;
18+
}
19+
1620
if (!config.container) { error("container"); }
1721
if (!config.items && !config.static) { error("items or static"); }
1822
};
@@ -73,6 +77,7 @@ var MagicGrid = function MagicGrid (config) {
7377
this.gutter = config.gutter || 25;
7478
this.maxColumns = config.maxColumns || false;
7579
this.useMin = config.useMin || false;
80+
this.useTransform = config.useTransform;
7681
this.animate = config.animate || false;
7782
this.started = false;
7883

@@ -90,10 +95,12 @@ MagicGrid.prototype.init = function init () {
9095
this.container.style.position = "relative";
9196

9297
for (var i = 0; i < this.items.length; i++) {
93-
this.items[i].style.position = "absolute";
98+
var style = this.items[i].style;
99+
100+
style.position = "absolute";
94101

95102
if (this.animate) {
96-
this.items[i].style.transition = "transform 0.2s ease";
103+
style.transition = (this.useTransform ? "transform" : "top, left") + " 0.2s ease";
97104
}
98105
}
99106

@@ -172,10 +179,16 @@ MagicGrid.prototype.positionItems = function positionItems () {
172179
var col = this.nextCol(cols, i);
173180
var item = this.items[i];
174181
var topGutter = col.height ? this.gutter : 0;
175-
var left = col.index * colWidth + wSpace;
176-
var top = col.height + topGutter;
182+
var left = col.index * colWidth + wSpace + "px";
183+
var top = col.height + topGutter + "px";
177184

178-
item.style.transform = "translate(" + left + "px, " + top + "px)";
185+
if(this.useTransform){
186+
item.style.transform = "translate(" + left + ", " + top + ")";
187+
}
188+
else{
189+
item.style.top = top;
190+
item.style.left = left;
191+
}
179192

180193
col.height += item.getBoundingClientRect().height + topGutter;
181194

dist/magic-grid.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "magic-grid",
3-
"version": "3.1.5",
3+
"version": "3.2.0",
44
"description": "Super lightweight javascript library for dynamic grid layouts.",
55
"main": "dist/magic-grid.cjs.js",
66
"module": "dist/magic-grid.esm.js",

src/index.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class MagicGrid {
3737
this.gutter = config.gutter || 25;
3838
this.maxColumns = config.maxColumns || false;
3939
this.useMin = config.useMin || false;
40+
this.useTransform = config.useTransform;
4041
this.animate = config.animate || false;
4142
this.started = false;
4243

@@ -54,10 +55,12 @@ class MagicGrid {
5455
this.container.style.position = "relative";
5556

5657
for (let i = 0; i < this.items.length; i++) {
57-
this.items[i].style.position = "absolute";
58+
let style = this.items[i].style;
59+
60+
style.position = "absolute";
5861

5962
if (this.animate) {
60-
this.items[i].style.transition = "transform 0.2s ease";
63+
style.transition = `${this.useTransform ? "transform" : "top, left"} 0.2s ease`;
6164
}
6265
}
6366

@@ -134,10 +137,16 @@ class MagicGrid {
134137
let col = this.nextCol(cols, i);
135138
let item = this.items[i];
136139
let topGutter = col.height ? this.gutter : 0;
137-
let left = col.index * colWidth + wSpace;
138-
let top = col.height + topGutter;
140+
let left = col.index * colWidth + wSpace + "px";
141+
let top = col.height + topGutter + "px";
139142

140-
item.style.transform = `translate(${left}px, ${top}px)`;
143+
if(this.useTransform){
144+
item.style.transform = `translate(${left}, ${top})`;
145+
}
146+
else{
147+
item.style.top = top;
148+
item.style.left = left;
149+
}
141150

142151
col.height += item.getBoundingClientRect().height + topGutter;
143152

src/utils.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ const checkParams = config => {
1313
throw new Error("No config object has been provided.");
1414
}
1515

16+
if(typeof config.useTransform !== "boolean"){
17+
config.useTransform = true;
18+
}
19+
1620
if (!config.container) error("container");
1721
if (!config.items && !config.static) error("items or static");
1822
};

0 commit comments

Comments
 (0)