Full Width Vertical Slider With jQuery and jQuery Tools
You may remember a post I made showing how to create a full width slider with a color changing background using jQuery & jQuery Cycle. It turned out to be a very popular post, and someone suggested that I try to figure out how a slider on another site was created and make a tutorial based on it. Well, here is that tutorial.
The slider in question is a one over at Volusion which is a eCommerce software company. Their slider uses the full width of the browser well & even works on my resolution of 1920×1080. So as suggested I decided to try and figure out how they created it. It turns out that they use a jQuery plugin/library called jQuery Tools however the version they use is quite old & it is much simpler to replicate the slider than it was when Volusion created it.
Volusion no longer use the slider that I show you how to create, so as reference here is a snap I took from back when they used it. Hopefully they don’t mind, if you are from Volusion & you do object to me using this image please send me an email using the contact form.
First off, let’s take a look at an example. You could just take a trip to Volusion’s website, but I’m sure you want to see a version I made instead. Well click the demo link below.

Okay. Now that you’ve checked out what we are going to create, let’s start off with the HTML we need.
The HTML
The HTML is actually quite simple. Here is what I used.
<div id="area">
<div id="scroller">
<div class="items">
<div class="item" style="background:#1E99BF;">
<a href="#" class="image"><img src="happy-octopus_color-1E99BF.png" alt="The Octopus Smiled With Joy!" width="900" height="300" title="The Octopus Smiled With Joy!" /></a>
</div>
<div class="item" style="background:#E0C128;">
<a href="#" class="image"><img src="my-eyes_color-E0C128.png" alt="Oh God! My Eyes!" width="900" height="300" title="Oh God! My Eyes!" /></a>
</div>
<div class="item" style="background:#A6B823;">
<a href="#" class="image"><img src="no-body_color-A6B823.png" alt="No Body To Go With!" width="900" height="300" title="No Body To Go With!" /></a>
</div>
<div class="item" style="background: url(bird-bg.png) repeat-x center 0;">
<a href="#" class="image"><img src="pole-dancing_color-1B1C30.png" alt="Pole Dancing Birdy Style!" width="900" height="300" title="Pole Dancing Birdy Style!" /></a>
</div>
</div>
</div>
<div class="navi"></div>
</div>
Okay. So I lied, it isn’t that simple. Let’s go through it a bit at a time. First off we have an element I’ve called #area this is just a container. You can keep it, change it, removed it, whatever works for your situation.
Next up is an important element. #scroller is the element we will hook the jQuery into and so is extremely important, it’s also the element we will apply some essential CSS too. We then move onto .items. This is the element jQuery Tools will use to find your items. Again it is essential, and although it’s class name can be changed, I’d recommend keeping it as items for simplicity.
Finally we have .item this is the element that is recognized by the jQuery Tools scroller as a page. So if you have multiple images/text etcetera inside an .item they will also move when next/prev is triggered. This also allows you to make carousels but that is outside of the scope of this tutorial.
Now you may notice some hard coded styling. Normally that is a bad idea, but in this case I think it’s acceptable. All we are doing is adding our images and hard coding via inline style our background colors. You may also notice that the last item has a repeating background. That is the great thing about this technique, you don’t have to just use colors. Just remember your background must repeat perfectly so that it will scale for users with large monitor resolutions.
Nearly forgot. The .navi element is for the scroller to automagically add in it’s navigation pips. The CSS to create it is available on the demo page by viewing the source.
Now, onto the CSS.
The CSS
I’m only going to show the essential code here. If you want to see the rest, view the demo & view the source code.
#scroller {
position:relative;
overflow:hidden;
height: 300px;
width: 100%;
margin: 100px 0 0 0;
}
#scroller .items {
position:absolute;
height:20000em;
width: 100%;
}
#scroller .items .item a.image {
display: block;
width: 900px;
height: 300px;
margin: 0 auto;
border: 0; /*Thanks to Rodboc for pointing this out...*/
}
So. Most, if not all, of this is essential and the whole thing has a chance not to work if you miss it out. Basically though we are setting our widths & heights, as well as overflow to stop spillage. We also set a ridiculous height for our .items element so it can contain all our .items without any problems. We also set our hyperlinks to be block elements so we can center them, if we don’t do this the margin centering will not work & our slider won’t look right as the images will be left aligned.
If there is anything in the CSS you don’t understand I’m always here to help so just drop me a question in the comments & I’ll answer it as best I can.
Okay, now onto the jQuery.
The jQuery
First you need to attach jQuery & jQuery Tools to your page. You can download them from their respective websites or you can just use these next two lines of HTML in your documents head.
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script> <script type="text/javascript" src="http://cdn.jquerytools.org/1.2.5/full/jquery.tools.min.js"></script>
Once you’ve done that we are ready to go.
$(function() {
$("#scroller").scrollable({
vertical: true,
circular: true,
speed: 1200
}).autoscroll({
interval: 5000
}).navigator();
});
Yep, it’s that simple. You can customize things as you like. The speed is how fast the animation runs & interval is the time between slides. If you want to customize things further you’d need to look at the jQuery Tools website’s scroller pages where you can see demos & all the available parameters/options.
Requested: Switching To Horizontal
To have the slides move horizontally instead of vertically is actually quite difficult due to the full width nature of the slider. First let’s take a look at a demo, be warned it is by no means perfect as it uses Javascript to update the width’s & position’s of elements in real time if the browser is resized.
First to the CSS adjustments needed.
/* root element for scrollable items */
#scroller .items {
position:absolute;
width:20000em;
}
#scroller .items .item {
width: 900px;
height: 300px;
float: left;
}
As you can see we have changed our huge height for a huge width. This is to make sure our container can hold an extremely large amount of slides, this causes a problem though. Our slider works by using 100% width and now our width is massive. Now the size of the slides won’t update on browser resize as setting each item to 100% will make is 20000ems rather than the browser width since it becomes 100% of it’s parent element.
To fix this we are going to use some jQuery to help resize each item & reposition the slider when the browser is resized. Let’s take a look at the new jQuery:
$(function() {
$("#scroller .item").css("width", $(document).width());
$("#scroller").scrollable({
circular: true,
speed: 1200
}).autoscroll({ interval: 5000 }).navigator();
api = $('#scroller').data("scrollable");
$(window).resize(function() {
if($('#scroller .items:animated').length == 0) {
$("#scroller .item").css("width", $(document).width());
nleft = $(document).width() * (api.getIndex() + 1);
$("#scroller .items").css("left", "-"+nleft+"px");
}
});
});
As you can see there are a few changes. I’ve highlighted the changes & we are only going to go through them. First off we make sure each of our items are the width of the browser when the DOM is loaded. Next you may notice that vertical: true is missing, you can either remove that line or set it to false.
We need to use the jQuery Tools API so we load it into a variable called, originally enough, api. Next we make a resize event which will trigger when the browser is resized. The function is actually pretty simple.
First we check to see if the slider is currently being animated, if it is we don’t want to do anything as it causes weirdness to happen. If it isn’t being animated we change the sizes of each item to the new browser width. Now we need to reposition the slider (.items) since resizing the browser has pushed it out of position, so we take the browser width & multiply it by the index of the current slide plus one, we add one since the slide index is counted from zero rather than one. Finally we set the left position of the .items container to the new left position we’ve calculated.
Horizontal Scrolling Fix
A small bug was pointed out by Gavrisimo in the comments. The problem is basically that if you resize the browser window while the slider is being animated you will have a problem with the width & position of the slider being incorrect. This is because the slider will not resize itself while it is animated to stop some very strange problems that occur. While it is not ideal if you want to use this style of slider here is a fix Gavrisimo kindly provided. It should be placed between lines 14 and 15 in the code above.
api.onSeek(function(event){
$("#scroller .item").css("width", $(document).width());
nleft = $(document).width() * (api.getIndex() + 1);
$("#scroller .items").css("left", "-"+nleft+"px");
});
The horizontal version of this slider is still flawed even with these fixes. If you want to use it, it is best to have the speed low & interval quite high. The speed being low makes the slider quicker giving less time for the user to resize their browser during the sliders animation.
That’s it. I hope this has been helpful. As always I try my best to preempt any questions you may have, but if you have any questions at all feel free to ask them in the comments & I’ll try my best to answer them.


Discussion: 73 Comments » add a comment
Hey Paul,
thanks, slide-wrapper is a class I wrapped the slider in, however, it only has overflow:hidden; right now.
They’re actually not stacking down, it’s actually not even showing the slide images, it’s showing the text that sits over top and a button that is assigned to each slide.
I built the entire slider into a custom post type in WordPress. Including the text, and button.
How would I have the slider hide until the js is loaded? It’s almost like it loads the slides smaller in width first, like all of them at 700px or something during the flash moment?
I dropped the file size some too, and they are web opt.
thanks for all the help man!
http://bit.ly/ql4GvV
Ahh, that would explain it, lol.
To be honest it looks fine for me in Chrome. The only way I know to hide it would be to set the containing element to display hidden, and then use the on before seek event to show it once loaded.
You don’t have an example of how to do this… Do you?
haha, I’m hitting google about it now, but any advice would be much appreciated!
I don’t, unfortunately. I’m not even sure it would work. You could instead just make the element hidden with CSS and add a bit of code to reveal it on DOM load. It might hide it for long enough to hide the flash.
thanks
Hi Sumesh,
No problem.
Hi!
I found a bug in IE7-IE8 with the border image, for fix it you need to add a property in “a.image” with the value “border: 0;”
Hi,
Never noticed that one, but you are right. Thanks. I’ve added it into the CSS for the post with a little credit to you in the comment.
Thanks again.
i’m using 1800px images for slides. When i specified the width of “#scroller” and “#scroller items” horizontal scroll appear. ?f i specified those two width 100% then, images doesn’t shown. Is there a solution for full width images?
Hmm thats strange. Try setting your width to 1800px again but see if setting overflow to hidden will stop the scroll bars. Im not sure which element youd need to do it on though as I dont have the code in front of me, im writing this on the WP app.
Hey,
Great slider and tutorial, thanks for sharing!
I just have one question..I’m not too familiar with js and I don’t understood how to add NEXT/PREV buttons, elements. Can you add a short description of how to do that?
Thanks so much!
Hi Catalin,
Thank you, and don’t worry I understand it can be confusing when you are just starting out with jQuery.
It’s not too difficult to add in the next/prev buttons. You just need to create two elements styled in a way you’d like using CSS and give them classes, you would normally use
next&prevbut you can use whatever you’d like. Then change the jQuery code from the tutorial to this:$(function() { $("#scroller").scrollable({ vertical: true, circular: true, speed: 1200, next: '.next', prev: '.prev' }).autoscroll({ interval: 5000 }).navigator(); });If you use different classes you’d change
.next&.prevto whatever you used.Does that help? Let me know if you need any further help.
Thankyou very much for this.
Thanks you so much for this. Question though, I’d like to use numbers instead of the circles for navigation. Can you tell me how to do this?
Hi Rebecca,
I’m not 100% but I think jQuery tools has an option in the navigator plugin to do it for you. You would just change the navigator part of the code to this:
.navigator({ 'indexed' : true });Basically adding
'indexed' : trueas an option to the navigator plugin should do it.Hope that helps.
Hi there, thank you very much for the slider.
I was wondering if there is a way to slide in the background color or image first (vertical or horizontal) and fade in the image with delay. I’ve tried it, but i’m not that good with js.
It would be great if you have a solution for it.
Hi Jasper,
Not so much with jQuery Tools, but it may be possible using jQuery Cycle. Take a look at my latest tutorial on custom transitions hopefully it will explain a little more on how it might be done, just imagine the image is the background & the caption is the image.
Hopefully that will help with the basics, but let me know if you need any further help.
Hello Everyone,
I would like to first say thank you.
I think the slide is fantastic..
But I can’t get the little bubbles on the bottom, I have a little experience coding.
could someone help..
Basically, I get the slider to work and the images change vertically, but the bubbles on the bottom don’t show..
I believe that bubbles are associated to the .navi item but after adding the code in my css file they don’t show..
Please help and thank you very much
Hi Paolo,
The most common problem is that the image, used by the slider, is missing. It’s normally included with the the jQuery tools package, but you can grab it here, if you need it.
If you do have the image & it’s linked in the CSS properly, let me know & I’ll see if I can help further.
Thank you for the kind word & hope that helps.
Paul,
Thank for you response.
I was able to get it to work on my home page.
What I want to do now is modify the characteristics a little bit.
I would like to have it work like a image gallery..
Instead of the bubbles on the bottom (which look great on my homepage), I would like it to scroll vertically but with a “previous” and “next” button (which I have).
How would I do this?
This post is great.. helped me out a lot..
Paolo
Hi Paolo,
The jQuery Tools plugin automatically looks for any elements with the class
nextorprevand makes them usable as next & previous buttons. If you want to change it you can supply custom ones to thescrollablefunction using the keysnextandprev.To disable the bubbles just remove the
navigator()function call from the jQuery code. So your jQuery might look something like:$(function() { $("#scroller").scrollable({ vertical: true, circular: true, speed: 1200, next: '.next', prev: '.prev' }).autoscroll({ interval: 5000 }) });Then just add in your elements with the class
next&prevand use CSS to style how you like.Hope that helps.
Paul,
Thank again for all your help.
Your reply really did help me, your jquery explanation was clear and understandable.
However, I’m getting tricked with the html and css part.
Admin edit: Your code was removed by WordPress (sadly). I’ve replied to the email you sent instead.
Thanks again Paul, even if you don’t respond I’m extremely grateful.