Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to center isotope in packery layout mode? #2

Open
Luxbit opened this issue Jul 30, 2014 · 5 comments
Open

How to center isotope in packery layout mode? #2

Luxbit opened this issue Jul 30, 2014 · 5 comments

Comments

@Luxbit
Copy link

Luxbit commented Jul 30, 2014

Hi there,

I'm trying to center the isotope container.
I found this http://jsfiddle.net/desandro/P6JGY/6/ and it works fine for Masonry, but I can't get it to work with the packery layout mode.

Any ideas?

Thanks

Best Regards

Koopax

@desandro
Copy link
Member

desandro commented Aug 2, 2014

Centering isn't a full-fledged feature for Packery. See metafizzy/packery#8 There is a hack solution, but I haven't tried it out for Isotope Packery layout mode. If you would like to see this feature please +1

@Luxbit
Copy link
Author

Luxbit commented Aug 11, 2014

+1

1 similar comment
@daweedm
Copy link

daweedm commented Sep 16, 2014

+1

@desandro
Copy link
Member

desandro commented Mar 2, 2015

Here's a solution. I put together this CodePen: http://codepen.io/desandro/pen/wBxvKe

// overwrite Packery methods
var PackeryMode = Isotope.LayoutMode.modes.packery;
var __resetLayout = PackeryMode.prototype._resetLayout;
PackeryMode.prototype._resetLayout = function() {
  __resetLayout.call( this );
  // reset packer
  var parentSize = getSize( this.element.parentNode );
  var colW = this.columnWidth + this.gutter;
  this.fitWidth = Math.floor( ( parentSize.innerWidth + this.gutter ) / colW ) * colW;
  this.packer.width = this.fitWidth;
  this.packer.height = Number.POSITIVE_INFINITY;
  this.packer.reset();
};

PackeryMode.prototype._getContainerSize = function() {
  // remove empty space from fit width
  var emptyWidth = 0;
  for ( var i=0, len = this.packer.spaces.length; i < len; i++ ) {
    var space = this.packer.spaces[i];
    if ( space.y === 0 && space.height === Number.POSITIVE_INFINITY ) {
      emptyWidth += space.width;
    }
  }

  return {
    width: this.fitWidth - this.gutter,
    height: this.maxY - this.gutter
  };
};

// always resize
PackeryMode.prototype.needsResizeLayout = function() {
  return true;
};

@principleCol
Copy link

+1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

4 participants