SpyreStudios

Web Design and Development Magazine

  • Design
  • Showcase
  • Inspirational
  • Tutorials
  • CSS
  • Resources
  • Tools
  • UX
  • More
    • Mobile
    • Usability
    • HTML5
    • Business
    • Freebies
    • Giveaway
    • About SpyreStudios
    • Advertise On SpyreStudios
    • Get In Touch With Us

Code a Dynamic Featured Image Gallery Layout using jQuery

March 22, 2013 by Jake Rocheleau

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 Demo – Download 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 Demo – Download 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.

Filed Under: Tutorial Tagged With: carousel, gallery, image, jquery, open source, plugin

Recent Posts

  • What Factors Determine the Best Digital Marketing Agency?
  • 31 Fresh Design Elements for Spring and Easter
  • 10 Templates for Music Concert Flyers
  • How to Build a Web Scraper Using Node.js
  • Best PHP Books, Courses and Tutorials in 2022

Archives

  • June 2022
  • April 2022
  • March 2022
  • February 2022
  • January 2022
  • December 2021
  • November 2021
  • October 2021
  • September 2021
  • August 2021
  • July 2021
  • June 2021
  • May 2021
  • April 2021
  • March 2021
  • February 2021
  • January 2021
  • December 2020
  • November 2020
  • October 2020
  • September 2020
  • August 2020
  • July 2020
  • June 2020
  • May 2020
  • April 2020
  • March 2020
  • February 2020
  • January 2020
  • December 2019
  • November 2019
  • October 2019
  • September 2019
  • August 2019
  • July 2019
  • June 2019
  • May 2019
  • April 2019
  • March 2019
  • February 2019
  • January 2019
  • December 2018
  • November 2018
  • October 2018
  • September 2018
  • August 2018
  • July 2018
  • June 2018
  • May 2018
  • April 2018
  • March 2018
  • February 2018
  • January 2018
  • December 2017
  • November 2017
  • October 2017
  • September 2017
  • August 2017
  • July 2017
  • June 2017
  • May 2017
  • April 2017
  • March 2017
  • February 2017
  • January 2017
  • December 2016
  • November 2016
  • October 2016
  • September 2016
  • August 2016
  • July 2016
  • June 2016
  • May 2016
  • April 2016
  • March 2016
  • February 2016
  • January 2016
  • December 2015
  • November 2015
  • October 2015
  • September 2015
  • August 2015
  • July 2015
  • June 2015
  • May 2015
  • April 2015
  • March 2015
  • February 2015
  • January 2015
  • December 2014
  • November 2014
  • October 2014
  • September 2014
  • August 2014
  • July 2014
  • June 2014
  • May 2014
  • April 2014
  • March 2014
  • February 2014
  • January 2014
  • December 2013
  • November 2013
  • October 2013
  • September 2013
  • August 2013
  • July 2013
  • June 2013
  • May 2013
  • April 2013
  • March 2013
  • February 2013
  • January 2013
  • December 2012
  • November 2012
  • October 2012
  • September 2012
  • August 2012
  • July 2012
  • June 2012
  • May 2012
  • April 2012
  • March 2012
  • February 2012
  • January 2012
  • December 2011
  • November 2011
  • October 2011
  • September 2011
  • August 2011
  • July 2011
  • June 2011
  • May 2011
  • April 2011
  • March 2011
  • February 2011
  • January 2011
  • December 2010
  • November 2010
  • October 2010
  • September 2010
  • August 2010
  • July 2010
  • June 2010
  • May 2010
  • April 2010
  • March 2010
  • February 2010
  • January 2010
  • December 2009
  • November 2009
  • October 2009
  • September 2009
  • August 2009
  • July 2009
  • June 2009
  • May 2009
  • April 2009
  • March 2009
  • February 2009
  • January 2009
  • December 2008
  • November 2008
  • October 2008
  • May 2008
  • April 2008

Categories

  • Accessibility
  • Android
  • Apps
  • Art
  • Article
  • Blogging
  • Books
  • Bootstrap
  • Business
  • CSS
  • Design
  • Development
  • Ecommerce
  • Fireworks
  • Flash
  • Freebies
  • Freelance
  • General
  • Giveaway
  • Graphic Design
  • HTML5
  • Icons
  • Illustrator
  • InDesign
  • Infographics
  • Inspirational
  • Interview
  • Jobs
  • jQuery
  • Learning
  • Logos
  • Matrix
  • Minimalism
  • Mobile
  • Motion Graphics
  • Music
  • News
  • Photoshop
  • PHP
  • Promoted
  • Rails
  • Resources
  • Showcase
  • Tools
  • Tutorial
  • Twitter
  • Typography
  • Uncategorized
  • Usability
  • UX
  • Wallpapers
  • Wireframing
  • WordPress
  • Work

Meta

  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org

SpyreStudios © 2022