Applying some golden ratio to my XPages app

Introduction

A Friday XPages and beer tonight and I decided to tackle a beauty-contest problem I was confronted with earlier this week.

In an XPages application I am mixing material design principles and bootstrap together, more specific I am using the CSS grid system in Bootstrap to display collections of data in a tiled display format (better known as cards).

Golden ratio

Bootsrap enables me to make the tiled display responsive so for xs devices I display max 1 card per row, sm devices max 2 cards, md or lg max 4 cards. This works well for the width of a card BUT to make the cards look more aesthetic/ecstatic I want to apply some golden ratio or divine proportions.

Gold Bootstrap

First I thought to look if there is something available out there and I came along Gold Bootstrap, since I am already using Bootstrap, but this did not help me.

DIY

So I decided to pop open a beer and do it myself. This turned out to be rather simple… with the help of the responsive bootstrap toolkit.

The code below will check the viewport and depending on which viewport change the height style property of a card. Since I do not want large cards for xs and sm devices I set a width of 90 pixels then. For md and lg devices the cards may grow in size (width & height) but respect this golden ratio:

(function($, document, window, viewport){
$(document).ready(function() {
console.log(‘Current breakpoint:’, viewport.current());

if( viewport.is(“<md”) ) {
$( ‘.card-holder .list-item’ ).css( ‘height’, ’90px’);
}

if (viewport.is(‘>sm’)){
var firstCard = $( “.card-holder” ).first();
var firstCardWidth = firstCard.width();
$( ‘.card-holder .list-item’ ).css( ‘height’, (firstCardWidth/1.618) + ‘px’);
}
});

$(window).resize(function(){
console.log(‘Current breakpoint:’, viewport.current());
if( viewport.is(“<md”) ) {
$( ‘.card-holder .list-item’ ).css( ‘height’, ’90px’);
}
if (viewport.is(‘>sm’)){
var firstCard = $( “.card-holder” ).first();
var firstCardWidth = firstCard.width();
$( ‘.card-holder .list-item’ ).css( ‘height’, (firstCardWidth/1.618) + ‘px’);
}
});

})(jQuery, document, window, ResponsiveBootstrapToolkit);

As a result I get smaller cards in xs and sm devices:

gold-sm

and bigger cards in a 4 column layout on md and lg devices which resize really nice:

gold-lg

Now I just need to fill up this additional landscape on a card with some usefull information…

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s