Skip to content

Commit 99b7d73

Browse files
committed
fixed 'gridWidth' bug
1 parent b3a4037 commit 99b7d73

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

dist/index.js

+13-6
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,10 @@
196196
return [];
197197
}
198198
},
199+
gridWidth: {
200+
type: Number,
201+
default: -1
202+
},
199203
cellWidth: {
200204
type: Number,
201205
default: 80
@@ -242,6 +246,9 @@
242246
}
243247
},
244248
computed: {
249+
gridResponsiveWidth: function() {
250+
return this.gridWidth < 0 ? this.windowWidth : Math.min(this.windowWidth, this.gridWidth);
251+
},
245252
height: function() {
246253
return Math.ceil(this.items.length / this.rowCount) * this.cellHeight;
247254
},
@@ -251,11 +258,11 @@
251258
};
252259
},
253260
rowCount: function() {
254-
return Math.floor(this.windowWidth / this.cellWidth);
261+
return Math.floor(this.gridResponsiveWidth / this.cellWidth);
255262
},
256263
rowShift: function() {
257264
if (this.center) {
258-
var contentWidth = this.items.length * this.cellWidth, rowShift = contentWidth < this.windowWidth ? (this.windowWidth - contentWidth) / 2 : this.windowWidth % this.cellWidth / 2;
265+
var contentWidth = this.items.length * this.cellWidth, rowShift = contentWidth < this.gridResponsiveWidth ? (this.gridResponsiveWidth - contentWidth) / 2 : this.gridResponsiveWidth % this.cellWidth / 2;
259266
return Math.floor(rowShift);
260267
}
261268
return 0;
@@ -494,9 +501,9 @@
494501
}
495502
};
496503
}, function(module, exports, __webpack_require__) {
497-
exports = module.exports = __webpack_require__(0)(), exports.push([ module.i, "\nbody {\n margin: 0;\n padding: 0;\n}\n.v-grid {\n display: block;\n position: relative;\n width: 100%;\n}\n", "" ]);
504+
exports = module.exports = __webpack_require__(0)(), exports.push([ module.i, ".v-grid{display:block;position:relative;width:100%}", "" ]);
498505
}, function(module, exports, __webpack_require__) {
499-
exports = module.exports = __webpack_require__(0)(), exports.push([ module.i, "\n.v-grid-item-wrapper {\n display: block;\n position: absolute;\n box-sizing: border-box;\n left: 0;\n top: 0;\n user-select: none;\n transform: translate3d(0px, 0px, 0px);\n z-index: 1;\n}\n.v-grid-item-wrapper.v-grid-item-animate {\n transition: transform 800ms ease;\n}\n", "" ]);
506+
exports = module.exports = __webpack_require__(0)(), exports.push([ module.i, ".v-grid-item-wrapper{display:block;position:absolute;box-sizing:border-box;left:0;top:0;user-select:none;transform:translateZ(0);z-index:1}.v-grid-item-animate{transition:transform .8s ease}", "" ]);
500507
}, function(module, exports, __webpack_require__) {
501508
__webpack_require__(14);
502509
var Component = __webpack_require__(1)(__webpack_require__(5), __webpack_require__(12), null, null);
@@ -561,11 +568,11 @@
561568
}, function(module, exports, __webpack_require__) {
562569
var content = __webpack_require__(8);
563570
"string" == typeof content && (content = [ [ module.i, content, "" ] ]), content.locals && (module.exports = content.locals);
564-
__webpack_require__(2)("0a97df14", content, !0);
571+
__webpack_require__(2)("105852af", content, !0);
565572
}, function(module, exports, __webpack_require__) {
566573
var content = __webpack_require__(9);
567574
"string" == typeof content && (content = [ [ module.i, content, "" ] ]), content.locals && (module.exports = content.locals);
568-
__webpack_require__(2)("4be927ea", content, !0);
575+
__webpack_require__(2)("38de0bc4", content, !0);
569576
}, function(module, exports) {
570577
module.exports = function(parentId, list) {
571578
for (var styles = [], newStyles = {}, i = 0; i < list.length; i++) {

src/Grid.vue

+4-4
Original file line numberDiff line numberDiff line change
@@ -108,15 +108,15 @@ export default {
108108
},
109109
110110
rowCount () {
111-
return Math.floor(this.windowWidth / this.cellWidth)
111+
return Math.floor(this.gridResponsiveWidth / this.cellWidth)
112112
},
113113
114114
rowShift () {
115115
if (this.center) {
116116
let contentWidth = this.items.length * this.cellWidth
117-
let rowShift = contentWidth < this.windowWidth
118-
? (this.windowWidth - contentWidth) / 2
119-
: (this.windowWidth % this.cellWidth) / 2
117+
let rowShift = contentWidth < this.gridResponsiveWidth
118+
? (this.gridResponsiveWidth - contentWidth) / 2
119+
: (this.gridResponsiveWidth % this.cellWidth) / 2
120120
121121
return Math.floor(rowShift)
122122
}

0 commit comments

Comments
 (0)