Image Gallery with TweenMax CSS3 effects and JQuery sauce

Recently Greensock added some new cool features to their animation JS Engine, these target specifically css3 animations and animating css3 properties.

So I thought to create a little demo showcasing some of these cool new features.

This Image gallery moves on 2 axis, horizontally for viewing different images and “vertically” or “in-time” if you prefer for viewing different galleries.

You can view a rough DEMO here


So lets start by defining our HTML elements:

<div class="timelineBox selectedTimeline gradeNow" id="cars2012" rel="2012">
             <label class="timelineLabel">CARS 2012</label>
             <div class="timelineBoxContainer">
               <div class="box"><img src="assets/car2012_1.jpg"/></div>
               <div class="box"><img src="assets/car2012_2.jpg"/></div>
               <div class="box"><img src="assets/car2012_3.jpg"/></div>
               <div class="box"><img src="assets/car2012_4.jpg"/></div>
           <div class="timelineBox" id="cars2000" rel="2000">
             <label class="timelineLabel">CARS 2000</label>
             <div class="timelineBoxContainer">
               <div class="box"><img src="assets/car2000_1.jpg"/></div>
               <div class="box"><img src="assets/car2000_2.jpg"/></div>
               <div class="box"><img src="assets/car2000_3.jpg"/></div>
               <div class="box"><img src="assets/car2000_4.jpg"/></div>
           <div class="timelineBox" id="cars1988" rel="1988">
             <label class="timelineLabel">CARS 1988</label>
             <div class="timelineBoxContainer">
               <div class="box"><img src="assets/car1988_1.jpg"/></div>
               <div class="box"><img src="assets/car1988_2.jpg"/></div>
               <div class="box"><img src="assets/car1988_3.jpg"/></div>
               <div class="box"><img src="assets/car1988_4.jpg"/></div>

These three div’s will be animated so that they look one older than the other with the “gradeNow” class div being focused whilst the others are off-focus.

Of course we need some css to make them adjust to place:

#cars2012 > .timelineBoxContainer {
  float: left;
  position: relative;
  height: 250px;
  left: 50%;
  margin-left: -416px;


#cars2012 > .timelineBoxContainer > .box {
  background-color: #F1F1F1;
  width: 108px;
  height: 108px;
  margin-right: 150px;
  float: left;
  position: relative;
  top: 108px;

Posting here only the cars2012 css code as it repeats for the other two categories.

And we move to the JS part for the “in-time” animation and effect by defining a function called “move to past”:

function moveToPast(grade,elem,delay){
    delay = 0;
  var carelem = elem;
  // 1 is older
    carelem.removeClass();,0.2,{css:{top:80,scaleX:0.25,scaleY:0.25,perspective:600}});".timelineBoxContainer").children(".box"),0.2,{css:{boxShadow: "0px 0px 24px 6px white",backgroundColor:"white",color:"#999"},onComplete:function(){
 ".timelineLabel"),0.2,{css:{textShadow:"0px 0px 25px white",color:'none'}});
    carelem.removeClass();,0.2,{css:{top:120,scaleX:0.5,scaleY:0.5,perspective:600},delay:delay});".timelineBoxContainer").children(".box"),0.2,{css:{boxShadow: "0px 0px 24px 6px white",backgroundColor:"white",color:"#999"},onComplete:function(){
    },delay:delay});".timelineLabel"),0.2,{css:{textShadow:"0px 0px 15px white",color:'none'},delay:delay});

What we do here is that we scale down and displace the other two categories so that they have a depth effect, we also apply some bluring with the following css code:

*Note: This CSS is only supported by latest chrome so far, so results may vary from browser to browser*

  filter: blur(5px);
  -webkit-filter: blur(5px);
  -moz-filter: blur(5px);
  -o-filter: blur(5px);
  -ms-filter: blur(5px);


  filter: blur(15px);
  -webkit-filter: blur(15px);
  -moz-filter: blur(15px);
  -o-filter: blur(15px);
  -ms-filter: blur(15px);


Now we need to create the animation and functionality that will move from one category to the other, so we setup an event listener:

    var thisObj = $(".selectedTimeline");$(".selectedTimeline"),1.2,{css:{scaleX:10,scaleY:10,autoAlpha:0,top:-20},onComplete:function(){

The initial part will scale and fade-out the focused category and swap places between the categories, for example if we had 2012 selected, now 2000 will become selected, 2012 will be last and 1988 will be second in line. The moveToNow function is the following:

function moveToNow(elem){
  currentSetLast = 4;
  currentSet = elem.attr('rel');
  if(currentSet == '2000'){
    currentSetMax = 4;
  else if(currentSet=='1988'){
    currentSetMax = 4;
    currentSetMax = 11;
  var carelem = elem;
  var boxes = carelem.children(".timelineBoxContainer").children(".box");
  var imgs  = boxes.children('img');
  var boxes = carelem.children(".timelineBoxContainer").children(".box");, 0.6, {css:{scaleX:1,scaleY:1,top:200}});'.timelineLabel'),0.3,{css:{textShadow:'0px 0px 0px black',color:'#f1f1f1'}});".timelineBoxContainer").children(".box"), 0.5, {css:{boxShadow: "0px 0px 10px 6px #131313"}});

What this does is to clean up the category div of any classes and give it new ones and also clean up the blur effects and make it look sharp

This completes our “in-time” rotation, but we also need to show more than just 4 images per category, TweenMax offers a cool way to show more images (this technique could be greatly improved if we use preloadJS or any preloading script for our images, but this is a rough demo to showcase some possibilities)

For the in-house category rotation we will setup a new event listener:


And the corresponding function along with some “global” variables:

var currentSetMax = 11;
var currentSetLast = 4;
var currentSet = '2012';

function rotateElem(amount,elem){
  var str = '50% 50%';
  console.log(str);'.box'), 3, {css:{rotationY:'+=180', transformOrigin:str,transformPerspective:800},onComplete:function(){
    var parent = elem.children('.box').children("img");,0.5,{css:{autoAlpha:1}});  
          currentSetLast = 0;
          currentSetLast += 1;
          currentSetLast += 1;

What we do here is to rotate each of the boxes, fadeout the images inside, load new images when the rotation ends and fadein the new images, when we are out of pictures we load from the beginning again

I really like the potential in this type of gallery so I will keep tweaking with it and post any new findings.

Meanwhile here is a DEMO and the complete code that was mentioned in this post.

*Note: The animation speed and performance may be different between browsers, and only “modern” browsers support most of the features that we used*

Tagged , , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *