Placed in: Home arrow Programming arrow Webdesign arrow Animated fullscreen background image slideshow
Animated fullscreen background image slideshow

Do you remember the Advanced jQuery background image slideshow I posted last year? Because of that tutorial, reader Evens sent me an e-mail, asking how the effect on the website from Climate Crisis could be recreated. It seemed liked an intersting thing to do, so I took the time to try to create the same effect.

With the help of some small HTML, nifty CSS and loads of jQuery, we're able to create an animated fullscreen background image slideshow. Read the rest of this article to learn how it's built.

Animated fullscreen background image slideshow using jQuery

You can easily change the script by changing some variables. It also features image preloading and keyboard navigation (try pressing the numeric keys). The background images have a width of 2000px, just to cover most of the currently used screen resolutions. Check out the demo what we're going to create!

Demo Animated fullscreen background image slideshow   Download Animated fullscreen background image slideshow

The script uses the Templates and Easing jQuery plugins. Tested and working on Firefox, Safari and Chrome. I've added a reference video below to show how the page should look like. As always, comments are left on the source code to explain what it does.

Video

Here's a reference video to show how the page should look like (displayed in Firefox).

Looks pretty cool, doesn't it? Now let's dive into the code!

HTML

Since the page is extremely dynamic, the HTML is very empty (everything is added by jQuery). We do need some handles to inject to, so this is everything we need.

 
<div id="navigationBoxes">
   <!-- Navigation boxes will get injected by jQuery -->  
</div>
 
<div id="pictureSlider">
   <!-- Pictures will be injected by jQuery -->
</div>

The #navigationBoxes is a container for the navigation boxes, and the #pictureSlider is the container for the background images. That's all the HTML we'll statically need for this script! Now let's dive into some CSS.

CSS

Below, you'll find a part of the CSS I created for this effect. Take note, it isn't complete (dive into the source code to see it fully). I've only selected some key properties, just to show you what's going on.

 
/* Hide scrollbars */
body { overflow:hidden; }
 
/* Pictures will have a fixed width/height, and pushed to the back */
#pictureSlider div {
   height:1000px; width:2000px; position:absolute; z-index:-999;
}
 
/* Since we have several navigation boxes, we'll need to use a class (not ID) */
.navbox {
   width:450px; height:300px; position:absolute; left:0px; top:50px;
}
 
/* The navigation for each navigation box is a list */
.navbox ul {
   list-style:none; position:absolute; right:10px; top:10px;
}
.navbox ul li {
   display:inline; cursor:pointer;
}
.navbox ul li a {
   display:block; float:left; background-image:url("../images/nav_btns.png");
   color:#eee; font: bold 14px Helvetica, Arial, Sans-serif; line-height:18px;
}
.navbox ul li a:hover {
   background-position:bottom; color:#000;
}
 
/* Special class for the link when the current navigation box is selected */
.navbox ul li a.active {
   color:#777;
}
 
/* CSS styling for the navigation box text */
.navbox h2 {
   font: bold 40px Helvetica, Arial, Sans-serif;
}
.navbox p a {
   text-decoration:none;  text-transform:uppercase; letter-spacing: 10px; color:#eee;
}
.navbox p a:hover {
   border-bottom:1px dotted;
}
.navbox p.bottom {
   position:absolute; bottom:5px; right:5px;
}

CSS

Nothing extremely hard going on over here (just take note of the width and height of some boxes, and the overflow). Now let's dive into the more interesting part: the jQuery.

jQuery

Now that we have the backbone of the page (HTML) and some of the styling is complete (CSS), let's add some interactivity using jQuery. I'll take you through this script I created (comments are already added) and explain what it does. First, we'll need some variables that we can use as settings for the page. These are the ones we need:

 
// Speed of the animation
var animationSpeed = 600;
 
// Type of easing to use; http://gsgd.co.uk/sandbox/jquery/easing/
var easing = "easeOutCubic";
 
// Variable to store the images we need to set as background
// which also includes some text and url's.
var photos = [ {
      "title" : "Aperture",
      "cssclass" : "cam",
      "image" : "bg_cam.jpg",
      "text" : "In optics, an aperture is a hole or an opening through TRIMMED",
      "url" : 'http://www.sxc.hu/photo/1270466',
      "urltext" : 'View picture'
   },
   // More "Photo" objects can be added
];
 
// 0-based index to set which picture to show first
var activeIndex = 0;
 
// Variable to store if the animation is playing or not
var isAnimating = false;

JavaScript

Take note of the photos array, which contains several Photo objects. You can add more, the script will detect them automatically. Also check the property names of the Photo objects, since we'll need to use them later.

As a matter of fact, we're going to use those properties already to create the navigation boxes. Since we need to add several navigation boxes (one for each image), I found the jQuery Templates plugin very useful. It iterates over the photos, applies the specified template, and appends it to another DOM object.

JavaScript

 
// Add the navigation boxes
$.template("navboxTemplate", "<div class='navbox ${cssclass}'>
   <ul></ul>
   <h2>${title}</h2>
   <p>${text}</p>
   <p class='bottom'><a href='${url}' title='${title}'>${urltext}</a></p>
</div>");
$.tmpl("navboxTemplate", photos).appendTo("#navigationBoxes");

I found this plugin to be working great, and to do exactly what I wanted.

As you can see, the template adds an empty ul to the navigation box. We'll need to add the actual (numeric) navigation there. We'll use some extra jQuery to do so. At this point, we're already iterating the photos array, and we pre-load the images as well.

 
// Add the navigation, based on the Photos
// We can't use templating here, since we need the index + append events etc.
var cache = [];
for(var i = 1; i < photos.length + 1; i++) {
   $("<a />")
      .html(i)
      .data("index", i-1)
      .attr("title", photos[i-1].title)
      .click(function() {
         showImage($(this));
      })
      .appendTo(
         $("<li />")
            .appendTo(".navbox ul")
      );
         
   // Preload the images
   // More info: http://engineeredweb.com/blog/09/12/preloading-images-jquery-and-javascript
   var cacheImage = $("<img />").attr("src", "images/" + photos[i-1]);
   cache.push(cacheImage);
}

JavaScript

When you click each item, it'll call the showImage function (we'll create it in the next step). Also note the index of each element will be passed on as a data attribute (not using HTML5 data-* attributes here). But first, before we create the showImage function, we need to make some final adjustments to the DOM:

 
// Set the correct "Active" classes to determine which navbox we're currently showing
$(".navbox").each(function(index) {
   var parentIndex = index + 1;
   $("ul li a", this).each(function(index) {
      if(parentIndex == (index + 1)) {
         $(this).addClass("active");
      }
   });
});
   
// Hide all the navigation boxes, except the one from current index
$(".navbox:not(:eq(" + activeIndex +"))").css('left', '-450px');
   
// Set the proper background image, based on the active index
$("<div />")
   .css({ 'background-image' : "url(images/" + photos[activeIndex].image + ")" } )
   .prependTo("#pictureSlider");

JavaScript

All done with that! Now it's the user interaction we need (the click event) in order to show another image based on the selected index. I hope the following code explains itself.

JavaScript

 
//
// Shows an image and plays the animation
//
var showImage = function(docElem) {
   // Retrieve the index we need to use
   var imageIndex = docElem.data("index");
   
   startAnimation(imageIndex);
};
   
//
// Starts the animation, based on the image index
//
var startAnimation = function(imageIndex) {
   // If the same number has been chosen, or the index is outside the
   // photos range, or we're already animating, do nothing
   if(activeIndex == imageIndex ||
      imageIndex > photos.length - 1 ||
      imageIndex < 0 ||
      isAnimating) {
      return;
   }
      
   isAnimating = true;
   animateNavigationBox(imageIndex);
   slideBackgroundPhoto(imageIndex);
      
   // Set the active index to the used image index
   activeIndex = imageIndex;      
};

Maybe you wonder why these two functions can't be combined to one? We'll need the startAnimation function for the keypress events. This function calls animateNavigationBox and slideBackgroundPhoto with the imageIndex, but what do those functions do? I'm glad you asked!

JavaScript

 
//
// Animate the navigation box
//
var animateNavigationBox = function(imageIndex) {
   
   // Hide the current navigation box
   $(".navbox").eq(activeIndex)
      .css({ 'z-index' : '998' }) // Push back
      .animate({ left : '-450px' }, animationSpeed, easing);
      
   // Show the accompanying navigation box
   $(".navbox").eq(imageIndex)
      .css({ 'z-index' : '999' }) // Push forward
      .animate({ left : '0px' }, animationSpeed, easing);
};
   
//
// Slides the background photos
//
var slideBackgroundPhoto = function(imageIndex) {
   // Retrieve the accompanying photo based on the index
   var photo = photos[imageIndex];
 
   // Create a new div and apply the CSS
   $("<div />")
      .css(
         {    'left' : '-2000px',
            'background-image' : "url(images/" + photo.image + ")" } )
      .addClass(photo.cssclass)
      .prependTo("#pictureSlider");
 
   // Slide all the pictures to the right
   $("#pictureSlider div").animate({ left : '+=2000px' }, animationSpeed, easing, function() {
      // Remove any picture that is currently outside the screen, only the first is visible
      $("#pictureSlider div:not(:first)").remove();
         
      // Animation is complete
      isAnimating = false;
   });
};

That's all we need to create this nifty effect! As a final touch, I've added keypress navigation.

 
// Register keypress events on the whole document
$(document).keypress(function(e) {
      
   // Keypress navigation
   // More info: http://stackoverflow.com/questions/302122/jquery-event-keypress-which-key-was-pressed
   if (!e.which && ((e.charCode || e.charCode === 0) ? e.charCode: e.keyCode)) {
       e.which = e.charCode || e.keyCode;
   }
      
   var imageIndex = e.which - 49; // The number "1" returns the keycode 49. We need to retrieve the 0-based index.
   startAnimation(imageIndex);
});

JavaScript

That's about it! As you can see, the HTML and CSS aren't that hard to understand, but the jQuery used is pretty intensive. Yet, the final effect looks pretty cool!

Conclusion and Download

I know the script isn't perfect; For some reason, the image preloading doesn't work fully. Also, the script only works for screens that have a resolution than 2000 x 1000px (that does cover most of the current screen resolutions though). Also, the user will never see the full image, some parts will be clipped off (a great alternative would be Supersized).

Other than that, I think it's a pretty cool effect to see!

Demo Animated fullscreen background image slideshow   Download Animated fullscreen background image slideshow

And what about you? Would you use this script in your next project? Do you see any room for improvement? Feel free to share!


Tags:  slideshow animated fullscreen jquery

Interested in this topic? You might enjoy another article I've written called

Did you like this article? Subscribe to my feed or email to keep updated on new articles.

Spread the word and submit to:
Digg!Reddit!Del.icio.us!Facebook!StumbleUpon!
Comments
Add NewSearchRSS
Anthony - Preeminent   2011-03-01 00:18:44
Gravatar image Looks fantastic on the widescreen Mac! I hate to be "THAT" guy, but how does this look in IE? I currently use Supersize for my large images, on my site. I will have to play around with this!
iopiop   2012-08-15 08:33:14
Gravatar image Other features of
Michael - Nice   2011-03-01 08:42:03
Gravatar image :lol:

It is quite quicker and smoother than Advanced jQuery background image slideshow

But it kinda sucks in IE....

Still, it brill.
Beben Koben - Prodigy of Head   2011-03-01 11:06:32
Gravatar image awesome master...thats great <img src=hock:' />
Marco - Thanks!   2011-03-04 06:45:19
Gravatar image Thanks guys! IE is indeed acting weird, it looks like as if this line of code doesn't work:
Quote:
$( ".navbox:not(:eq( " + activeIndex +" ))" ).css( 'left', '-450px' );

This prevents the navigation boxes to be displayed.

Little "workaround" is to simply hit a number: The animation will go, and the correct box will show.. Strange IE!
LK   2011-04-05 06:26:39
Gravatar image hi, need help on IE to show the navigation box. not quite understand the "Little workarround" as mentioned. thx
Rory - Damn!   2011-03-07 16:14:26
Gravatar image Thats the sexiest thing I've seen all day, definitely using this. Thank you so much
Register Web Domain   2011-03-08 09:51:04
Gravatar image Image slideshow makes the website look better. I have sent this link to my developer and will let you know on the working of the code.
Fleur - It does work with IE as well   2011-03-17 19:09:54
Gravatar image Marco, dank je wel!

This is exactly what I was looking for. I'm designing an intranet for a dealership and this works perfectly. Thanks so much. We use Windows 7 with IE 8 and there's no problem at all.

Veel succes.
Fleur - re: It does work with IE as well   2011-03-17 19:20:02
Gravatar image Sorry - I just see I posted this in the wrong section -
I meant to post it under the Advanced jQuery background image slide show.


Fleur wrote:
Marco, dank je wel!

This is exactly what I was looking for. I'm designing an intranet for a dealership and this works perfectly. Thanks so much. We use Windows 7 with IE 8 and there's no problem at all.

Veel succes.
Minh Nguyen - Minh Nguyen On Tech   2011-03-19 17:28:46
Gravatar image That's awesome Marco. Thank you!
e11world - Multimedia Design & Development   2011-03-24 22:15:43
Gravatar image I guess it's safe to say that I can change the transition to a fade instead of the slide. It just seems a bit too much when it's on a big resolution after you see it a few times. Great tutorial and thank you very much for that!
Seraphyn - A little bit Offtopic but   2011-03-25 19:07:09
Gravatar image Thanks for nice Blog and Go on, hope we will see instead of:
Results 1 - 15 of 337
a little bit leeter: Results 1 - 15 of 1337
Nice Job and nice impressions for new ideas for building up new templates.
Thanks
Chris
hoangloi - wow good idea   2011-03-27 16:33:02
Gravatar image with this idea we can have an about page. use wordpress :D
example:
when i'm a children.... :lol:
when i'm a boy.... :whistle: ...bla bla...
it's fun and unique
i like it. and thanks marco. your website alway are inspirations better
swag - Mr.   2011-03-31 18:34:22
Gravatar image First off, great tutorial. I've shared it with others.
Some my slides won't have a url. How would I work through removing the href/ID?



"title" : "",
"image" : "flower.jpg",
"url" : "",
"firstline" : "some copy goes here",
"secondline" : "more copy goes here"
security - thanks   2011-04-02 10:37:11
Gravatar image thanks good slide..
Jools Moore - Adding fancybox for links?   2011-04-18 12:13:50
Gravatar image Hi Marco,

Thanks for this - it looks awesome. I'd like to modify it to make a nice simple website, and I was wondering if it's possible to integrate Fancybox or similar for the links, so that clicking will bring up a window on the page for additional html, text, images, etc...

A messy version of what I'm doing is here:
http://www.naked-ape.co.uk/JMcomms/index2.html

Also, is it possible to make the links into images in the script.js - I've got them showing as a background for the links, but it would be best to do it properly!!

great work, anyway! thanks...

Jools
chris george - Web Design Company   2011-04-21 04:49:41
Gravatar image As a Web Design Company India CYBERMOUNT is one of the fastest growing web site designing company spreading wings in USA UK and India. Expertise in Web Designing, Web Applications and Online Marketing.
Nash - Animated background Auto play Slide show   2011-05-04 04:45:54
Gravatar image Hi,

I found this so much worth, using this background stylee slideshow make me independent to use big size images in html layout.

This is perfect, but i want little more with this banner effect and the more is "Auto Play" function along with navigation

Could it be possible that when banner loads it start playing automatically along with navigation?

please guide or show me the way if it is possible.

Thanks
im kim sue yap   2011-05-21 14:50:52
Gravatar image beautiful!!!
laurie - TEMPLATES CSS   2011-06-14 17:19:12
Gravatar image I create a lot of my own templates if anyone needs any help feel free to contact me. Great Website!
maggi - Belstaff Blouson   2011-08-06 02:13:35
Gravatar image
Techmug   2011-08-16 11:59:39
Gravatar image I have created slideshow with the help of souece code
Thats a very beautiful yeh
pradeep - Animated background Auto play Slide show   2011-09-05 13:37:43
Gravatar image
Nash wrote:
Hi,

I found this so much worth, using this background stylee slideshow make me independent to use big size images in html layout.

This is perfect, but i want little more with this banner effect and the more is "Auto Play" function along with navigation

Could it be possible that when banner loads it start playing automatically along with navigation?

please guide or show me the way if it is possible.

Thanks
COACH PURSE,CHANEL PURSE and H - COACH PURSE,CHANEL PURSE and HERMES PURSE   2011-11-04 09:00:52
Gravatar image A woman's purse can often reflect her personal qualities, without holding a package on different occasions more can show your personal charisma.If you like a wallet is missing, we ALLPURSE.COM. Here we provide you with world class COACH PURSE,CHANEL PURSE and HERMES PURSE.At the same time we also have a discount.What are you looking forward to come on friends. Join us and have a wonderful time!
Dev - load file instead of text   2012-02-13 11:25:43
Gravatar image Really outstanding and beautiful.
Is it possible to load an html, text or php file instead of the 'text' line.
I also want to add pictures and stuff instead of only one textline. Unfortunately all html is stripped or gives an error when i want html tags in the 'text'
Matt - preloaded background   2012-03-08 21:35:44
Gravatar image use css 'hack' for preloading all background like this
#picture-slide {
background-image: url("images/bg_key1.jpg";);
background-image: url("images/bg_key2.jpg";);
background-image: url("images/bg_key3.jpg";);
background-image: url("images/bg_key4.jpg";); }
paid directory list - Nice Js   2012-03-30 16:55:34
Gravatar image Nice Js,

It's work
Web Dizayn   2012-03-31 09:53:05
Gravatar image Nice work.Thank you
Web Dizayn - Nice   2012-03-31 09:53:43
Gravatar image Nice work.Thank you..
Dan - Help   2012-04-04 08:03:41
Gravatar image Anyone knows how to do background gallery which is activated by button, and the images are preloaded automatically becauce there is 150 images. I need that the images would change very fast. I would be very thankful for that.
Louboutin   2012-04-06 08:22:04
Gravatar image TLC identification method for erhuang was a QiangBai rhubarb, appear very some aren't: http://www.ferragamoshoesoutletonline.com/
Louboutin UK   2012-05-17 05:02:07
Gravatar image Lopez's failure to americans, including the south began to establish new Latin America slave owners from colonial empire in the mysterious awake,
Gucci Belts - Gucci Belts   2012-06-15 08:44:09
Gravatar image Although the German venture was scuttled shortly after its inception .
Lenny - best looking slider   2012-06-20 19:15:33
Gravatar image best looking slider I've seen!

I'd like to use this on a website I'm building, only with the navigation in a separate div that doesn't animate. Any ideas how I could do this?
Kath   2012-07-04 08:12:27
Gravatar image how can you make the images clickable?
Thanks!
Kath   2012-07-04 08:13:07
Gravatar image how do you make the images into a link?
meet a dominant women - Nice   2012-07-09 14:52:36
Gravatar image I guess it's safe to say that I can change the transition to a fade instead of the slide. It just seems a bit too much when it's on a big resolution after you see it a few times. Great tutorial and thank you very much for that!
ibunno   2012-09-24 07:47:22
Gravatar image
Makro Web   2012-10-03 22:20:44
Gravatar image Thanks for download link
Kiba   2012-10-05 17:26:05
Gravatar image It doesn't work on IE...
Is there a solution for this problem?

Thank you.
Anonymous   2012-11-13 01:45:56
Gravatar image
diPPas - Bug found   2013-03-07 18:09:50
Gravatar image Hey i just found a bug in your .js

here where it preloads images:

var cacheImage = $("";).attr("src", "resources/js/slider/images/" + photos[i-1]);

I found that returns a 404 :

http://www.clunl.edu.pt/new/resources/js/slider/images/%5Bobject%20Object%5D

in order to fix that 404 I did this:

var cacheImage = $("";).attr("src", "resources/js/slider/images/" + photos[i-1].image);

Hope I helped
mohsen - thank you   2013-04-25 03:50:49
Gravatar image very good.
tnx.
mohsen - thank you   2013-04-25 03:51:50
Gravatar image very good.
tnx.
Read more...
Name:
Email:
  Gravatar enabled.
Website:
Title:
UBBCode:
[b] [i] [u] [url] [quote] [code] [img] 
 
 
:angry::0:confused::cheer:B):evil::silly::dry::lol::kiss::D:pinch:
:(:shock::X:side::):P:unsure::woohoo::huh::whistle:;):s
:!::?::idea::arrow:
 
Security Image
Please input the anti-spam code that you can read in the image.
Unsubscribe from e-mail notifications.
 
< Prev   Next >
Subscribe

Subscribe to Marcofolio