在更改其他项目的大小后,我想将较小的项目移动到空白空间。
这是它在 jsfiddle 上的样子:http: //jsfiddle.net/FRH8v/
例如,当您单击否时。2,你会得到它上面的两个空格。如何移动较小的物品来填充这些空间?
这是代码(与 jsfiddle 相同):
$(function(){
// Modified Isotope methods for gutters in masonry
$.Isotope.prototype._getMasonryGutterColumns = function() {
var gutter = this.options.masonry && this.options.masonry.gutterWidth || 0;
containerWidth = this.element.width();
this.masonry.columnWidth = this.options.masonry && this.options.masonry.columnWidth ||
// Or use the size of the first item
this.$filteredAtoms.outerWidth(true) ||
// If there's no items, use size of container
containerWidth;
this.masonry.columnWidth += gutter;
this.masonry.cols = Math.floor((containerWidth + gutter) / this.masonry.columnWidth);
this.masonry.cols = Math.max(this.masonry.cols, 1);
};
$.Isotope.prototype._masonryReset = function() {
// Layout-specific props
this.masonry = {};
// FIXME shouldn't have to call this again
this._getMasonryGutterColumns();
var i = this.masonry.cols;
this.masonry.colYs = [];
while (i--) {
this.masonry.colYs.push(0);
}
};
$.Isotope.prototype._masonryResizeChanged = function() {
var prevSegments = this.masonry.cols;
// Update cols/rows
this._getMasonryGutterColumns();
// Return if updated cols/rows is not equal to previous
return (this.masonry.cols !== prevSegments);
};
var $container = $('#container'),
$element = '.element';
$container.isotope({
itemSelector: $element,
resizable: false,
transformsEnabled: true,
animationEngine: 'best-available',
layout: 'masonry',
masonry: {
gutterWidth: 4,
columnWidth: 157
}
});
// click action
$container.find($element).each(function(){
var that = $(this);
that.click(function(){
if( that.hasClass('active') ){
$container.find($element).removeClass('active');
} else {
$container.find($element).removeClass('active');
that.addClass('active');
}
$container.isotope('reLayout');
return false;
});
});
});