jSquares for jQuery October 22, 2009 42 Comments
If you’ve viewed my “lab” section, that is a perfect example of what this is. jSquares is a jQuery plugin that pops up an image and a description in an overlay on hover. It is basically identical to the image grid found on www.ted.com. Works like a charm in IE6+, FF 3+, Safari 3+ and Opera 10.
Setting it up
Make sure you’re including these files in the head of your document
<script src="http://www.google.com/jsapi" type="text/javascript"></script>
<script type="text/javascript">google.load("jquery","1.3.2");</script>
<link rel="stylesheet" href="css/jsquares.css" type="text/css" media="all" />
<script src="js/jquery.jsquares.min.js" type="text/javascript"></script>To initiate jSquares simply wrap it in the jQuerys document ready function like so.
<script type="text/javascript"> $(document).ready(function(){ $('#js-container').jsquares(); }); </script>
The default chunk of HTML will look something like this:
<div id="js-container"> <div class="js-image"> <a href="#wolf!"><img class="js-small-image" src="images/wolf-moon.jpg"/></a> <div class="js-small-caption"> <span>Howlla at cha boy!</span> </div> <div class="js-overlay-caption-content"> <h4>You can't hide from wolf boy.</h4> <p> Lorem ipsum dolor sit amet, consectetur adipiscing elit. In elementum arcu non orci fermentum nec suscipit neque dignissim... <a href="#">Read more »</a> </p> </div> </div> </div>
Optional parameters
Parameters can be added when you call jsquares like so:
$('#js-container').jsquares({ shuffle_in: false, // have the pictures all fade in on page load? fade_on_hover: false, // do we want the images to fade on hover or just change opacity? caption_slide_down: false // do we want the caption to slide down or just appear? });
Here’s a list of all of the options it can take:
| Key | Default Value | Type | Description |
|---|---|---|---|
| image | .js-image | String | The target element holding all of the info (image/caption). View the source of the demo for a better understanding. |
| caption | .js-small-caption | String | The target element holding the caption. This element is found within the element specified as js_image. |
| caption_overlay_spacing | 12 | Integer | This is the padding on the caption that pops up on hover. |
| caption_width | 400 | Integer | This is the width of the caption that pops up on hover. |
| caption_height | 130 | Integer | This is the height of the caption that pops up on hover. |
| fade_to | .3 | Integer | Float | This is the opacity that you want the images/captions to fade to when you roll over an image. |
| fade_start | 1 | Integer | Float | This is opacity that images/captions are sent back to after you roll off the image set. This normally shouldn’t be altered. |
| shuffle_in | true | Boolean | By default the images will shuffle in (fade in) randomly. If you don’t want any effects and to have them just appear, change this to false. |
| shuffle_in_speed | 130 | Integer | If js_shuffle_in is set to true, you can set the speed in which images appear one after the other. |
| fade_on_hover | true | Boolean | By default the images fade to a value set by js_fade_to, if you just want them to change opacity then change this to false. |
| caption_slide_down | true | Boolean | The caption has a slide down effect when you hover over an image. If you just want it to appear instead of sliding down, change this to false. |
| caption_slidedown_speed | fast | String | Integer | If the option key js_caption_slide_down is set to true, you can change the speed that it slides down at. |
Any comments/suggestions are definitely encouraged. Enjoy!

The js is very nicely written. Well done.
1. To be able to change the image inside the overlay, different to the one on display.
2. To change the size of the overlay in conjunction with the size of the image. I have a large image that is 250*250 and the overlay size is 400*250. My smaller image is 140*140 and I would like the overlay to be 140*400.
A great example would be the design of Tiffany the jewellers
http://uk.tiffany.com/Shopping/CategoryBrowse.aspx?cid=579740&mcat=148206
Is it possible to lightbox the images? I think if that could work, then it would be more functional, so that you could see images in more detail.
Thoughts?
Thanks!
One comment, as an additional setting, it would be better in my opinion if we could chose wether to use onClick or OnMouseOver event to launch to caption.
Thanks for this great piece of work!
@Jamie: All scripts are licensed under the GPL. You can go ahead and use it in any of your projects.
@Kathy: You would need to elaborate more, but I don't for-see any problems. JSON is just a data format.
If you have the time, could you explain how you integrate this with wordpress. I've created a loop to get posts and pass title, thumbnail and excerpt to the jSquare boxes but I end up with the same post in all the windows. I have a feeling it's something to do with the box array and needing to put the posts data into it. If you could tell me what words I should google to find out info please let me know.
Have a great weekend Jordan and thanks again
Thanks Jordan