29 lines
1.1 KiB
JavaScript
29 lines
1.1 KiB
JavaScript
export default class AGrid extends window.AObject {
|
|
constructor(options = { "element": null, "grid": "row", "columns": 3, "gutter": "5", "easing":"bounce"}) {
|
|
this.ele = document.querySelector(options.element);
|
|
this.wWidth = window.innerWidth || document.body.clientWidth;
|
|
this.options = options;
|
|
this.updateWidth();
|
|
}
|
|
checkColumn() {
|
|
this.hItem = 0;
|
|
if (Array.isArray(this.options.columns)) {
|
|
for (var i = 0; i < this.options.columns.length; i++) {
|
|
if (this.wWidth < this.options.columns[i][0]) {
|
|
this.col = this.options.columns[i][1];
|
|
if (this.options.columns[i].length > 2) {
|
|
this.hItem = this.options.columns[i][2];
|
|
}
|
|
}
|
|
}
|
|
} else {
|
|
this.col = this.options.columns;
|
|
}
|
|
|
|
}
|
|
updateWidth() {
|
|
this.cWidth = this.ele.clientWidth;
|
|
this.checkColumn();
|
|
this.wCol = (this.cWidth - (this.options.gutter * (this.col - 1))) / this.col;
|
|
}
|
|
} |