Подтвердить что ты не робот

Центрирование изотопов jQuery

Возможный дубликат:
Как центрировать DIV в DIV?

Пожалуйста, взгляните на изображение ниже:

enter image description here

Как сделать серые квадраты горизонтально центрированными внутри красного контейнера div? Все это сделано с изотопом, поэтому, пожалуйста, помните об этом.

Спасибо заранее.

enter image description hereenter image description here

Даже если родительский (красный) div всегда выровнен по середине, серые, меньшие - нет. В верхнем изображении, когда они выровнены в одном столбце, этот столбец должен находиться в точной середине обертки (красный) div.

4b9b3361

Ответ 1

На самом деле очень просто реализовать центрирование для Isotope (только что закончил сайт, который делает это, чтобы хорошо выглядеть на мобильных сенсорных устройствах, а также на настольных устройствах). Вы просто включаете этот бит кода из репозитория David DeSandro до обычного кода Isotope в конце этого блока

<!-- centered layout extension http://isotope.metafizzy.co/ --> 

<script type="text/javascript">
$.Isotope.prototype._getCenteredMasonryColumns = function() {

    this.width = this.element.width();

    var parentWidth = this.element.parent().width();

    var colW = this.options.masonry && this.options.masonry.columnWidth || // i.e. options.masonry && options.masonry.columnWidth

    this.$filteredAtoms.outerWidth(true) || // or use the size of the first item

    parentWidth; // if there no items, use size of container

    var cols = Math.floor(parentWidth / colW);

    cols = Math.max(cols, 1);

    this.masonry.cols = cols; // i.e. this.masonry.cols = ....
    this.masonry.columnWidth = colW; // i.e. this.masonry.columnWidth = ...
};

$.Isotope.prototype._masonryReset = function() {

    this.masonry = {}; // layout-specific props
    this._getCenteredMasonryColumns(); // FIXME shouldn't have to call this again

    var i = this.masonry.cols;

    this.masonry.colYs = [];
        while (i--) {
        this.masonry.colYs.push(0);
    }
};

$.Isotope.prototype._masonryResizeChanged = function() {

    var prevColCount = this.masonry.cols;

    this._getCenteredMasonryColumns(); // get updated colCount
    return (this.masonry.cols !== prevColCount);
};

$.Isotope.prototype._masonryGetContainerSize = function() {

    var unusedCols = 0,

    i = this.masonry.cols;
        while (--i) { // count unused columns
        if (this.masonry.colYs[i] !== 0) {
            break;
        }
        unusedCols++;
    }

    return {
        height: Math.max.apply(Math, this.masonry.colYs),
        width: (this.masonry.cols - unusedCols) * this.masonry.columnWidth // fit container to columns that have been used;
    };
};
</script>

И тогда вы просто установили изотоп как обычно

<script type="text/javascript">
$(function() {
    var $container = $('#container');
    // the usual stuff for layouting, sorting, filtering, limiting clicks to zones...
</script>

Ответ 2

найдено самое простое решение. Используйте макет кладки внутри изотопа:

$container.isotope({ 
  itemSelector: '.pbox', 
  layoutMode: 'masonry',
  masonry: { 
    isFitWidth: true 
  }
});