Sliding Boxes and Captions

18 January 2010 Monday

This application was viewed 773 times




Sliding Boxes and Captions

Pictures, blurb, whatever your fancy - this jQuery technique makes you look that much cooler (than you already are!).

View The DEMO

The Basic Idea

All of these sliding box animations work on the same basic idea. There is a div tag (.boxgrid in my css) that essentially acts as a window where two other items of your choosing “peek” through.

Confused? Cue the helpful diagram -

 

From this basic idea we can play around with animations of the sliding element to either show or cover up the viewing area, thus creating the sliding effect.

Step 1 – CSS Foundation Work

Given the basic structure outlined in the helpful image above, we will need to use a little bit of CSS to make it work as intended. The following will make it functional -  review my complete stylesheet in the downloadable file.

The following defines the viewing window (.boxgrid) and sets the default position for images within it to the top left. This is important to make the overlap while sliding work. Dont’ forget that overflow:hidden makes this all possible.

  1. .boxgrid{   
  2.     width325px;   
  3.     height260px;   
  4.     margin:10px;   
  5.     float:left;   
  6.     background:#161613;   
  7.     bordersolid 2px #8399AF;   
  8.     overflowhidden;   
  9.     positionrelative;   
  10. }   
  11. .boxgrid img{   
  12.     positionabsolute;   
  13.     top: 0;   
  14.     left: 0;   
  15.     border: 0;   
  16. }  

If you aren’t using the semi-transparent captions you are done with CSS – move to Step 2.

  1. .boxcaption{   
  2.     floatleft;   
  3.     positionabsolute;   
  4.     background#000;   
  5.     height100px;   
  6.     width: 100%;   
  7.     opacity: .8;   
  8.     /* For IE 5-7 */  
  9.     filter: progid:DXImageTransform.Microsoft.Alpha(Opacity=80);   
  10.     /* For IE 8 */  
  11.     -MS-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=80)";   
  12.     }  

Opacity that plays nice in all browsers is a rough topic, educate yourself if you need to.

Now we’ll need to set up the default starting point for the caption box. If you want it fully hidden initially, you will want the distance from the top or left to match the height or width of the window (.boxgrid), depending on which direction it will be sliding. You can also have it partially visible initially, as .caption .boxcaption illustrates.

  1. .captionfull .boxcaption {   
  2.     top: 260;   
  3.     left: 0;   
  4. }   
  5. .caption .boxcaption {   
  6.     top: 220;   
  7.     left: 0;   
  8. }  

Step 2 – Adding the Sliding Animations

This next stage is a matter of choosing which animation suites you, I have included a bunch of pre-formatted potentials to help you along. Play around with them to find one that fits your needs and style.

  1. $(document).ready(function(){   
  2.     //To switch directions up/down and left/right just place a "-" in front of the top/left attribute   
  3.     //Vertical Sliding   
  4.     $(´.boxgrid.slidedown´).hover(function(){   
  5.         $(".cover"this).stop().animate({top:´-260px´},{queue:false,duration:300});   
  6.     }, function() {   
  7.         $(".cover"this).stop().animate({top:´0px´},{queue:false,duration:300});   
  8.     });   
  9.     //Horizontal Sliding   
  10.     $(´.boxgrid.slideright´).hover(function(){   
  11.         $(".cover"this).stop().animate({left:´325px´},{queue:false,duration:300});   
  12.     }, function() {   
  13.         $(".cover"this).stop().animate({left:´0px´},{queue:false,duration:300});   
  14.     });   
  15.     //Diagnal Sliding   
  16.     $(´.boxgrid.thecombo´).hover(function(){   
  17.         $(".cover"this).stop().animate({top:´260px´, left:´325px´},{queue:false,duration:300});   
  18.     }, function() {   
  19.         $(".cover"this).stop().animate({top:´0px´, left:´0px´},{queue:false,duration:300});   
  20.     });   
  21.     //Partial Sliding (Only show some of background)   
  22.     $(´.boxgrid.peek´).hover(function(){   
  23.         $(".cover"this).stop().animate({top:´90px´},{queue:false,duration:160});   
  24.     }, function() {   
  25.         $(".cover"this).stop().animate({top:´0px´},{queue:false,duration:160});   
  26.     });   
  27.     //Full Caption Sliding (Hidden to Visible)   
  28.     $(´.boxgrid.captionfull´).hover(function(){   
  29.         $(".cover"this).stop().animate({top:´160px´},{queue:false,duration:160});   
  30.     }, function() {   
  31.         $(".cover"this).stop().animate({top:´260px´},{queue:false,duration:160});   
  32.     });   
  33.     //Caption Sliding (Partially Hidden to Visible)   
  34.     $(´.boxgrid.caption´).hover(function(){   
  35.         $(".cover"this).stop().animate({top:´160px´},{queue:false,duration:160});   
  36.     }, function() {   
  37.         $(".cover"this).stop().animate({top:´220px´},{queue:false,duration:160});   
  38.     });   
  39. });  

Step 3 – The HTML

There are a few classes that we created simply as selectors for JQuery. Keep these rules in mind:

  • The div class “.cover” should be assigned to whatever is doing the sliding/movement.
  • Within the div .boxgrid, the img should always come first.

Here’s an example of the HTML I would use for the .captionfull animation:

  1. <div class="boxgrid captionfull">  
  2.     <img src="jareck.jpg"/>  
  3.     <div class="cover boxcaption">  
  4.         <h3>Jarek Kubicki</h3>  
  5.         <p>Artist<br/><a href="<A class=linkification-ext title="Linkification: http://www.nonsensesociety.com/2009/03/art-by-jarek-kubicki/" href="http://www.nonsensesociety.com/2009/03/art-by-jarek-kubicki/">http://www.nonsensesociety.com/2009/03/art-by-jarek-kubicki/</A>target="_BLANK">More Work</a></p>  
  6.     </div>  
  7. </div>  

Go Forth and Create

I’ve only touched upon a few options you have, these boxes are your canvases, create away. I would encourage you to download the attached files, as it may be easiest to just copy-paste the parts relevant to your project.

Tags: sliding, boxes, captions,


Sliding Boxes and CaptionsBookmark and Share

You write your thoughts

Please login to post comments here from the right corner.

your add
icon free icon icon set vector icon free catalog catalog template jquery news ticker widget tools tutorial php slider video youtube effects menu thumbnail forms facebook zoom image combo multiselect modal polaroid gallery expand code feedback contact navigation slider tagcloud Skateboard psd templates files badges subscribe panel login temlate file free office holland free template tabs prototype css scriptaculous opacity moo autocomplete wordpress themes design theme button images photoshop fonts font nav pdf logo style high javascript pretty photo jqery lightbox Themes Blog popular blog desing joomla xhtml brushes hair footer admin mootols slide show blackbox new download class first plugin upload browse Page effect modalbox web application urlitooltips sliding boxes captions flatchat chat ajax messaging browser hoverlightbox CSS Dev General Javascript PHP SQL search avatar vector Drupal Joomla Oscommerce javaScript phototype manager ajaxplorer flash xml rotator bookmarking pageflip slideshow poll text component script mediaplayer imagegallery pictograms car poster player mp3 radio onlineradio navigations drop-down collection brush tree textures paper pop-up bumpbox web2.0 iphone film frame twitter page fan mail delete dynamic calender form handbook city social paint timeline clock connect bar sharing accordion quotes ticker photo-effects background 3D media player graphic rss leaf green glossy bubble icon comic clean cool web 2.0 png actionscript ietter rotating Menu animated textured site masking pasword app layer sponge bob popup bubble tooltips horizontal prototip tooltip pack charachters comics blog action icon.psd flavour navi tango gradients istanbul mixed css3 sleek animations program html5 website Layer styles ultimate candy Media icons dropdown snow icon innerfade hover sub tag