Code a Dynamic Featured Image Gallery Layout using jQuery




The common image thumbnail carousel effect has gained traction among web developers. You can locate this technique on almost any major news company or online magazine, coupled with rotating featured images or banner designs. I feel that open source code has offered a much smoother choice for developers instead of being forced to write your own scripts.

In this tutorial I want to demonstrate how we can build a small layout wrapped around a full image gallery carousel. I will be using the Pikachoose jQuery plugin for this example. I believe the library is still very new, but the functionality is beautiful. And the very basic CSS classes are easy to edit if you spend a bit of time lurking in the files.

pikachoose slideshow image carousel jquery plugin demo screenshot

Live DemoDownload Source Code

Getting Started

The first step is to download a copy of the Pikachoose library from Github. This will contain a large number of demos along with the core files. This pack also includes the default jQuery carousel plugin file which is needed to get the carousel images working properly. Here is my sample header code from the main page document.

<!doctype html>
<html lang="en-US">
<head>
  <meta http-equiv="Content-Type" content="text/html;charset=utf-8">
  <title>Image Gallery Webpage using Pikachoose</title>
  <meta name="author" content="Jake Rocheleau">
  <link rel="shortcut icon" href="http://spyrestudios.com/favicon.ico">
  <link rel="icon" href="http://spyrestudios.com/favicon.ico">
  <link rel="stylesheet" type="text/css" media="all" href="http://fonts.googleapis.com/css?family=Galindo">
  <link type="text/css" rel="stylesheet" media="all" href="css/styles.css">
  <script type="text/javascript" src=" https://ajax.googleapis.com/ajax/libs/jquery/1.6/jquery.js"></script>
  <script type="text/javascript" src="js/jquery.jcarousel.min.js"></script>
  <script type="text/javascript" src="js/jquery.pikachoose.js"></script>
<!--[if lt IE 9]>
  <script type="text/javascript" src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
</head>

There are a lot of different files included within the header but none of them are super complicated. First we have some unique Google Webfonts along with my default stylesheet. This is followed by a recent copy of the jQuery library along with the carousel and Pikachoose plugins. The HTML5shiv document isn’t required but it is a nice touch for older legacy versions of Internet Explorer.

The nice thing about this image slideshow is that each object is contained inside an unordered list. So all of the thumbnail links are actually generated dynamically by jQuery. The internal content may still be crawled by Google, however the thumbnail images are exactly the same as your regular gallery images.

  <ul id="imgcarousel" class="jcarousel-skin-pika">
	<!-- http://www.hellandheavennet.com/image/final-fantasy-12/fmv-screenshots/310.jpg -->
	  <li><img src="images/01-ivalice-flying-airships.png"><span>Airships flying over Ivalice</span></li>

	  <!-- http://www.hellandheavennet.com/image/final-fantasy-12/fmv-screenshots/101.jpg -->
	  <li><img src="images/02-imperial-city-archades.png"><span>The Imperial City of Archades</span></li>

	  <!-- http://www.hellandheavennet.com/image/final-fantasy-12/fmv-screenshots/313.jpg -->
	  <li><img src="images/03-moogle-friend-ffxii.png"><span>A friendly Moogle</span></li>

	  <!-- http://www.hellandheavennet.com/image/final-fantasy-12/fmv-screenshots/308.jpg -->
	  <li><img src="images/04-balthier-sky-pirate.png"><span>Balthier the leading man</span></li>

	  <!-- http://www.hellandheavennet.com/image/final-fantasy-12/fmv-screenshots/302.jpg -->
	  <li><img src="images/05-the-group-balthier-vaan.png"><span>Balthier, Fran, Vaan, and Basch</span></li>

	  <!-- http://www.hellandheavennet.com/image/final-fantasy-12/fmv-screenshots/311.jpg -->
	  <li><img src="images/06-rassler-lady-ashe-wedding.png"><span>Lord Rasler of Nabradia and Lady Ashe of Dalmasca</span></li>
  </ul>

It is possible to include an external link inside the HTML if you want to link out from the image. I have skipped over this method and instead placed the attribution inside HTML comments. The inline span elements hold the caption text which is loaded dynamically after switching onto a new image. You can see this effect in each part of my demo codes.

Designing with CSS

I want to move onto my CSS stylesheet which is abundant with particular code snippets. Specifically I have copied over most of the Pikachoose default codes so that we only need a single lone CSS file. This will reduce the number of HTTP requests and general loading time of the page.

/*******************************/
/**** PikaChoose CSS styles ****/
/*******************************/

/* Style the thumbnails */
.pika-thumbs{ 
  padding: 0 16px; 
  height: auto; 
}
.pika-thumbs li { 
  width: 144px; 
  height: auto;
  margin: 10px 0 0 17px; 
  padding: 0; 
  overflow: hidden;
  float: left; 
  list-style-type: none;
  padding: 3px; 
  margin: 0 5px; 
  background: #fafafa; 
  border: 1px solid #e5e5e5; 
  cursor: pointer;
}

.pika-thumbs li .clip {
  position: relative;
  height: auto;
  text-align: center; 
  vertical-align: middle; 
  overflow: hidden;
}
.pika-thumbs li img {
  -webkit-transition: all 0.15s linear;
  -moz-transition: all 0.15s linear;
  transition: all 0.15s linear;
}
.pika-thumbs li img.active { -webkit-transition: none; -moz-transition: none; transition: none; }
.pika-thumbs li img:hover {
  opacity: 1.0;
}
	
/* The stage is the wrapper. The image fills 100% the height of the stage */
.pika-stage, .pika-textnav { width: 650px; display: inline-block; }

.pika-stage {
  position: relative; 
  background: #fafafa; 
  border: 1px solid #e5e5e5; 
  padding: 10px 10px 40px 10px; 
  text-align: center; 
  -webkit-box-sizing: content-box; 
  -moz-box-sizing: content-box; 
  box-sizing: content-box;
  height: 380px;
  overflow: hidden;
}

.pika-stage img { height: 100%; }

.pika-stage .caption {
  position: absolute; 
  background-color: #000; 
  background-color: rgba(0,0,0,0.7); 
  font-size: 1.1em;
  font-weight: bold; 
  color: #fafafa; 
  padding: 10px; 
  padding-right: 18px;
  text-align: right; 
  bottom: 50px; 
  right: 10px;
}
.pika-stage .caption p {padding: 0; margin: 0; line-height: 14px;}

There is a lot of stuff here about setting the container and page sizes. All of the width values are extremely important because this slideshow was created with a fixed width value. Pikachoose has this setup by default since the images were not designed to resize. You will find lots more classes for the image caption and carousel container in this stylesheet.

* The play, pause, prev and next buttons */
.pika-imgnav a {position: absolute; text-indent: -5000px; display: block;z-index:3;}
	.pika-imgnav a.previous {background: url('prev.png') no-repeat left 45%; height: 85%; width: 50px; top: 10px; left: 10px;cursor:pointer;}
	.pika-imgnav a.next {background: url('next.png') no-repeat right 45%; height: 85%; width: 50px; top: 10px; right: 10px;cursor:pointer;}

.jcarousel-skin-pika .jcarousel-container-horizontal { 
  width: 650px; 
  padding: 15px 10px; 
  margin-right: 10px; 
  overflow: hidden; 
  -webkit-box-sizing: content-box; 
  -moz-box-sizing: content-box; 
  box-sizing: content-box;
}
.jcarousel-skin-pika .jcarousel-clip-horizontal { height: auto; }
.jcarousel-skin-pika .jcarousel-item-horizontal { margin-right: 10px;}

/* The previous and next textual buttons */
.pika-textnav { overflow: hidden; margin: 10px 0 0 0; bottom: 3px; position: absolute; }
.pika-textnav a { font-size: 12px; text-decoration: none; color: #454545; padding: 8px; cursor: pointer; }
.pika-textnav a:hover { color: #111; }
	.pika-textnav a.previous {float: left; width: auto; display: block;}
	.pika-textnav a.next {float: right; width: auto; display: block;}

I do feel that the buttons add a bit of extra flair to the project. Of course you may choose to skip these buttons entirely and change the slideshow interface to render without them. In my example I have the play/pause buttons completely removed from the template. But it is easy to change these settings and design them to look anyway you want.

Look through the various styles here and pinpoint the changes you want to make. I did not spend a lot of time changing values, but instead reading over the documentation and looking into how the original demo was coded. I believe that fixed widths can dramatically impact the look & feel of your image carousel. Play around with my settings and do not be afraid to experiment!

Pikachoose JavaScript

The final block of code is a jQuery function call to initiate Pikachoose. The method is very simple and does not require a whole lot of parameters. Since the plugin already requires 3 external files I did not want to move this code into another file we would need to include. So instead I’ve appended this chunk of jQuery into my HTML page just before the final closing </body> tag.

$(function (){
  $("#imgcarousel").PikaChoose({
    carousel:true,
    transition:[1],
    carouselOptions:{wrap:'circular'}
  });
});

I think the most interesting part of these codes is the parameter setup. Typically jQuery will not care which order you pass in the different settings. But I have noticed instances where Pikachoose will not initiate properly without the transitions listing. I only want to use the 1st effect in the array set, but you could look at all of them to decide which works the best.

Ultimately the Pikachoose slider is very small and easy to contain within any webpage layout. But it does require a lot of customization inside the default CSS. Because of this drawback many developers will not be bothered to create with the project. Which is unfortunate, because it is a very powerful library for displaying image content in a unique slideshow. Check out my sample project demo below and feel free to download a copy of my source codes for practicing on your own.

pikachoose slideshow image carousel jquery plugin demo screenshot

Live DemoDownload Source Code

Final Thoughts

I cannot say that Pikachoose is the absolute best choice for all image galleries. There are many other free solutions which have also been written in jQuery, which may differ on various levels. I think it is worth noting how this library is very lightweight and is easily customized by editing the internal files. But Pikachoose also comes with a litany of additional demos which you can study for a maximal effect in your own website.


Jake Rocheleau

About the author:

Jake is a creative designer, illustrator, and web developer. He frequently writes articles involving new-age design concepts and freelance management skills. You can find him in Google or follow his tweets @jakerocheleau

Comments:

Scroll back to the top
Content


Receive the top stories from SpyreStudios and the Splashpress Media network every week, right in your Inbox. Relevant and timely content is yours for FREE!