npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

gallerygrid

v1.1.0

Published

A simple and lightweight image gallery grid layouter

Downloads

107

Readme

GalleryGrid.js

A simple and lightweight JavaScript image gallery grid layouter. The generated layout is similar to Google+ and Flickr (explained here and here) and scales well to hundreds of pictures. Check the included demo or see it in real-world use here.

Installation

Download

Download the dist/gallerygrid.js or the minified dist/gallerygrid.min.js and include it into your site. These standalone distributable files need jQuery (tested with jQuery 3.1.0) which is not included.

Package managers

npm: npm install gallerygrid --save

Bower: bower install gallerygrid.js --save

Usage

GalleryGrid needs a certain HTML structure with CSS formatting. The required HTML is a container (e.g. a div or ul) that contains items (e.g. div or li) that contain an image (e.g. img or svg) and anything else to enrich the item. Images should have data-width and data-height attributes that contain the image size in pixels, which is required to calculate the grid before the images are loaded. If you cannot provide these attributes, you need to defer application of the grid until all images are loaded, so the sizes can be read from HTML5 attributes.

CSS formatting must be applied to make sure that the container and items have zero padding (padding: 0;) and the items must also be displayed as inline blocks (display: inline-block;). There must not be any whitespaces (including line breaks) between end and start tags of items or browsers will render a space between the items that breaks the layout.

A GalleryGrid object is created and used like this:

// create an instance
// container can be a CSS selector, DOM element or jQuery element
var grid = new GalleryGrid(container, {
  // options: given values are the default values
  // thickness of the border around an item in pixels, which is the sum of css margin and border properties
  border: 0,
  // ideal pixel height that a row in the layout should have
  targetHeight: 250,
  // minimum container width at which the layout will be applied (useful to apply a responsive alternative layout [e.g. pure CSS] to extremely small screen sizes)
  minWidth: 0,
  // automatically update the layout when the window size changes.
  updateOnResize: true,
  // selector for the actual element to resize within an item (will be an img most of the time, but can be an svg too or any other element that has a size)
  itemSelector: 'img'
});

// instance methods
// apply layout to container
grid.apply();

// update layout
// e.g. when container size has changed and updateOnResize is false
// method is only executed when the container size has changed
grid.update();

// forced layout update
// to be used when the items have changed but the container size stays the same (e.g. when new items are added dynamically)
grid.update(true);

// remove the layout
grid.clear();

Example code

Here is a minimum example to get the grid working as expected. You can also check the source code of the demo or this website for more advanced examples.

HTML:

<ul id="gridcontainer">
  <li>
    <img src="...">
  </li><li> <!-- note the missing space between end and start tags -->
    <img src="...">
  </li>
</div>

CSS:

ul#gridcontainer {
  padding: 0;
}
ul#gridcontainer li {
  list-style: none;
  padding: 0;
  display: inline-block;
}
ul#gridcontainer li img {
  vertical-align: middle;
}

JS:

new GalleryGrid('#gridcontainer').apply();

License

Copyright (c) 2015, 2016 Mario Guggenberger [email protected]. Released under the MIT License.