I used some interesting jquery tricks(at least to me) to make the projects page more visually appealing; read on to learn how it was made. This is the beginning of a series on updates to the overall blog that I will post as I continue to learn more about both the Ruby Jekyll gem and web design in general.
The projects page was designed using jquery and a neat javascript library called slidesjs(slidesjs.com). Slidesjs is a simple yet elegant slideshow library with many special features such as the ability to add captions and various transition effects to your slides.
I choose to use it mainly because I found the documentaion well prepared(slidesjs.com/#doc), on the site you’ll find the rest of the features I won’t touch on in this article.This first part of the project page is the underlying html file, in this file you’ll notice the structure of the main div tag which holds the sildes_container. From within the slides_container you just add your slides and content as a div tag with the class slide; and from there you can put whatever you want into it.
Below is a copy of an early version of the projects page which was adapted from the “images with captions” example from slidesjs. The only real change I made(excluding the image sources and caption content) is the last div tag at the bottom,
this div tag allows me to swap out the contents of the projects page as you move across the slideshow using jquery which we’ll cover after the CSS bit.
<ahref="http://www.flickr.com/photos/bu7amd/3447416780/"title="&ldquo;I must go down to the sea again, to the lonely sea and the sky; and all I ask is a tall ship and a star to steer her by.&rdquo; | Flickr - Photo Sharing!"target="_blank"><imgsrc="/images/slidesjs/slide-5.jpg"width="570"height="270"alt="Slide 5"></a>
<divclass="caption">
&ldquo;I must go down to the sea again, to the lonely sea and the sky...&rdquo;
<ahref="http://www.flickr.com/photos/aftab/3152515428/"title="Save my love for loneliness | Flickr - Photo Sharing!"target="_blank"><imgsrc="/images/slidesjs/slide-7.jpg"width="570"height="270"alt="Slide 7"></a>
Finally here is the javascript code for the projects page which calls the slidesjs library animation functions. The main addition here is the showDescription(), it takes the div tag I mentioned before and extracts the current visible slides’ content and displays it on every page transition.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
$(function(){
$('#slides').slides({
preload: true,
preloadImage: '/images/slidesjs/loading.gif',
play: 0,
pause: 2500,
hoverPause: true,
animationStart: function(current){
},
animationComplete: function(current){
showDescription();
},
slidesLoaded: function() {
showDescription();
}
});
functionshowDescription() {
//slide content
var $sc = $('div.slide').filter(function() {
returnthis.style.display !== 'none';
});
//caption
var cap = $sc.children('div.caption').html();
$('div#project-description').html(cap);
}
});
Of particular merit here is the jquery filter function. What this allows us to do is to basically only extract the sole visible slide from the div holding the slides by looking at the display property.
In addition the jquery children function lets us run what is basically a sub-query on a given jquery object. From my perspective I could have easily just included the children search in the original query but I tend to keep queries short and simple to help the code remain easy to read.
Well that about wraps up how I put together the projects page… be sure to visit the projects page every once in a while.