A dynamic grid layout that let's you choose how many rows and columns of items are shown. Partly based on the visualization of Google Trends, except that you can add transitions.

You have surely seen the latest cool visualization of Google Trends, where the latest hot searches from Google Trends are shown in a colorful grid and where you can control the amount of items with a little grid control in the top left corner.

Regardless of the great swipe effect in the grid boxes, we really loved the idea of changing a layout dynamically with a control. Another great thing is that the boxes’ dimensions are percentage-based which makes them fluid. We couldn’t help but wonder how it would look if we’d added transitions to the grid where we could actually see what’s happening when changing from a let’s say 5 × 5 layout to a 2 × 3 one.

So we tried to create something similar: a dynamic grid layout where we can choose to have transitions with or without delays. The transition itself is set in the JavaScript, but in the CSS we can define what happens to the items that disappear (for example, scale down or rotate, etc.).

Please note that this only works as intended in browsers that support the respective CSS properties.

What we are doing is to calculate the positions and the dimensions of the boxes and set them according to the chosen grid layout. The values are percentage-based which makes the boxes fluid. Once we change the grid layout, a special class will be applied to the items that need to be hidden (i.e. the once we won’t see in the viewport anymore) which will optionally trigger a transition and do what you define in the class to be done (for example, scale them down or rotate them) and hide them.

For eventual rounding errors we are using calc() to add one pixel to the calculated percentage. Although that might not be the perfectly correct value, it will avoid the appearance of gaps between the items. For browsers that don’t support calc(), * [W]e’ll be adding half a percent to the width and height to avoid any gaps. *Woah, Safari does not seem to like transitioning to a calc() value at all: https://bugs.webkit.org/show_bug.cgi?id=100568. That does not seem to be resolved. So now we are using the fallback for every browser.

Note that Modernizr is used for detecting the support for calc() and touch. We are also using classie.js by David De Sandro.

An example for how to initialize the grid is the following:

Grid.init( { transition : true, speed : 450, delay: 20 } );

Demos

Check out the demos with the different configurations:

We hope you like and enjoy it and find it useful!