Full Width Vertical Slider With jQuery and jQuery Tools

/ Javascript, jQuery / by Paul Robinson / 97 Comments
This post was published back on June 13, 2011 and may be outdated. Please use caution when following older tutorials or using older code. After reading be sure to check for newer procedures or updates to code.

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.

Snap of Volusion's old full width vertical slider, used for reference.

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.

Preview of Full Width Vertical Slider Using jQuery & jQuery Tools

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.

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.

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.

Once you’ve done that we are ready to go.

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.

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:

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.

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.

97 Comments

Author’s gravatar

Thanks for another great tutorial. I love the way the slides scroll vertically.

Reply
Author’s gravatar author

Thank you MssBee, I’m glad you enjoyed reading it.

I loved that about it too, that’s one of the reasons I decided to go ahead & try to figure out how it was made.

Author’s gravatar

Thank you so much! That’s great work! I will make sure my friends are going to visit your website.

Author’s gravatar author

Thank you Marc. I’m always appreciative of anyone who spreads the word about Return True.

Look out for the new design due up and running sometime in the next week or so. 🙂

Author’s gravatar

Wonderfull! Thanks voor de great tutorial. I was wondering if it’s also possible to make this as a Full Width Horizontal Slider?

Reply
Author’s gravatar author

Hi Marc,

glad you liked the tutorial. It is possible to use the same slider, but have the slides move horizontally. I’m adding how to do it to the bottom of the post now, check back in a little while.

Author’s gravatar

How to add next and prev button? i’m new in jquery please tell me how to do that.

Reply
Author’s gravatar author

Hi Alex,

You just simply place an element with the class prev & the class next and jQuery Tools does the rest. Apply an image of your choosing to each one via the background using CSS similar to how the navigation pips are applied on the demo, and you are done.

Author’s gravatar

Hi! Good job! But – how to switch off pause on mouseover? Regards

Reply
Author’s gravatar author

Hi Michal,

To disable to pause on mouseover you add in the autopause: false option to the autoscroll method. For example:

Author’s gravatar

Hey Paul,

amazing article, its 6:30am here and I’m still not going to bed because of this tutorial… 🙂

I have only one issue i was hoping you can help me resolve – if you set speed: 3000 or something bigger and resize browser while it is animating the widths will be all wrong.

So this seems like a good solution to me:

http://pastie.org/2190630

Any ideas how to improve on this? 🙂

Reply
Author’s gravatar author

Hi Gavrisimo,

I never considered if the animation time was so slow & so close to the interval. The reason the width doesn’t correct is simply because the resize will only work if the scroller isn’t animating, and because the times are so close together it is never not animated.

Your solution is about the best I can see. It jerks it into place once the onSeek event completes, but there isn’t much that can be done.

I would advise not having the speed & interval so close together, or if they must be, you could try to use animate to reset the width & left position. It may look a little more acceptable, if you know what I mean.

Thank you for the contribution though, an outstanding thought. 🙂

Author’s gravatar

Hey Paul,

speed and interval so close together doesn’t really matter. The only thing here that matters is speed being slow enough for you to actually resize window a bit. 🙂

So just to recap, if you have your window on something smaller then your full resolution and when animation kicks in your resize to something bigger you can see that there are leftovers of nearby slide on the right side. The size of that left over is equal to what you resized that window.

http://www.screenr.com/Jd2s

Here is maybe even little better code… 🙂

http://pastie.org/2191756

Reply
Author’s gravatar author

Ahh, yes I see what you mean. Resizing the window during the animation and then not resizing again (without the seek fix) will not correct the sizing problem until the next slide.

Having the speed & interval too close together does cause a problem though as the slider will nearly always be animated leaving it without the ability to smoothly (rather than sharply) correct the width/left position.

I’ll add your fix to the post as it’s clearly needed to correct that problem.

Author’s gravatar

True, it doesn’t look good and it can throw your slideshow way off… 🙂

So if you use this horizontal technique then don’t use values for speed and interval that are really close one to another… 🙂

Reply
Author’s gravatar author

Well. The best thing is a low speed & high interval. That will make the slide happen quickly, but the time between slides longer. That means the likelihood of the visitor resizing the browser during the animation is reduced considerably.

I’ve added your code to the post above. Thanks again for providing it. 🙂

Author’s gravatar

Hey me again… 🙂 Again with small fix:

http://pastie.org/2194603

What this does is that adds a flag when window resize happens and then every time slide is done sliding it first checks for that flag before calling FixContainerWidth() function. It’s just to be safe, i had some small strange quirks and i thought it might be because this function is being called each and every time one slide is done sliding.

Reply
Author’s gravatar

Dear Paul,
I appreciate effort You put into tutorial. I use the solution You put here to create horizontal slider but from 1680px width photos but facing issues that comes from the fact in lower resolutions (after resize browser window photos are not centered and they’re cut-off)
Notice: the overflow-x:hidden value is necessary to avoid horizontal scrollbar appear.

Link: http://groovepixel.com/demos/redin/

I will appreciate Your help. I tried to digg sources on the web but unsuccessfully.

Reply
Author’s gravatar author

Hi Tom,

You seem to have misunderstood this tutorial slightly. You can’t really use full width images like that. Not only because you end up with this in a resolution such as mine, but because (as you have said) it doesn’t scale correctly.

A full width slider such as this one is best used with a block color background, or a repeated pattern background image with an image that is the layout’s maximum width in the center. Similar to what the demo in the post shows.

Author’s gravatar

Hi Paul,
First of all I would like to thank You for quick response.
I understand now. But.. do You know any resources which may be helpfull in my case?

Thank You in advance

Reply
Author’s gravatar author

Not that I’m aware of. The reason the images don’t stay in the center as the window is resized is simply because everything in a browser works from the top left to the bottom right. So as the browser is resized, as soon as the image hits the left edge it only scales from the right.

The same happens with your text content if you continue to scale the browser window. As soon as the text hits the left edge it stops centering.

Your best bet is to somehow make your images 960px (which seems to be your content width) and somehow fade them or integrate them graphically into a repeated or block color background.

There is currently no way that I know of to resize the actual images based on browser window size without them being pushed out of proportion.

Also I would advise against using the horizontal scrolling method as it only works with a few Javascript hack provided in the post & in the comments here. It is more of a technical demo than something to use in production. The vertical scroll is perfectly usable though.

Author’s gravatar

Thank You Paul.
I found the sample of effect I want to achive.

http://www.twofold.com/

I saw that pics are 1920px width and even the browser window resizes they remains centered.

Reply
Author’s gravatar author

That is created by cleverly using absolute positioning on the slider. By doing that you remove the slider from document flow avoiding the problem with the images sticking to the left of your browser. I hadn’t thought about that.

There is still a problem with the fact that if your have a larger resolution, and granted not many people have a resolution bigger than 1920×1080, you end up with a horrible problem as your images aren’t big enough.

They also use a slider I only recently found called anything slider. If you decided to use it, please let me know what it’s like, I’ve been wanting to use it but haven’t had the opportunity to yet.

Author’s gravatar

Hi Paul,
I successfully made it working by using absolute positioning as You mentioned and Your slider as well.

I guess it works fine now.
I had no opportunity to test it on the highter resolutions but at mine works fine (1680×1050 display screen).

Thank You for all guidance Paul!
I much appreciate Your involve.

Tom

Reply
Author’s gravatar

Please can you tell me how can I make this fade in and out instead of vertical scroll?

Reply
Author’s gravatar author

Hi Fiona,

You can’t fade this one in & out. Unfortunately the plugin used only scrolls. You could try my other full width slider tutorial though as that has a fade effect. You would just miss out the code that changes the background color if you don’t want it.

Author’s gravatar

Hello 🙂

My slider works fine – http://www.demo.redin.pl but I am facing issue how to implement easeOut easeIn function.

Maybe some of You had some issue before ?

I will be thankfull for Your suggestions.

Reply
Author’s gravatar author

Hi Tom,

I haven’t used the easing before, but from what I can see you just need to attach the jQuery easing plugin and then use the name of one in the easing parameter of jQuery Tools Scrollable.

Author’s gravatar

Hello, I would like to know how to make the navigator buttons appear layered on top of the entire slider .

Example of what I mean:
http://www.mediasignage.com/
(Notice the navigator circle buttons are above and on top of the over-all slider)

I have already changed the image navigator.png, now all I need is to hover that css over the slider I tried changing the z-index. Still no luck.
Your help with this greatly appreciated! 🙂

Reply
Author’s gravatar

Never mind I figured it out. In case someone wants to know, I added the code “position: relative;” under the “.navi {” in the css area of the demo. Then I placed its margin at “-280px auto;” Thanks for this awesome script! It’s exactly what I needed. XD

Author’s gravatar

@Andrew

If you are using z-index you also must use position: absolute.

Reply
Author’s gravatar author

Glad you figured it out Andrew & no worries. 🙂

Thanks for the addition Gavrisimo.

Author’s gravatar

How would I add text/image over top of the slides?

It’s a positioning issue. When I moves around from screen size to screen size?

I need it to sit in the same place on each slide?

Any thoughts?

<div class="item" style="background:url(/images/slides/rday_app_slide.jpg) no-repeat center top; height:650px;”>

<img src="/images/slides/rday-app-headline.png” alt=”TIME TO BE LOUDER THEN EVER BEFORE”>

test again

READ MORE

Reply
Author’s gravatar author

I’m not sure what you mean Andre.

If you place text in the slide it will stay in position within the slide element, but will move with the slide element should the browser be resized.

Author’s gravatar

Hey Paul,

<li class="slide-fake-1" style="background:url(/images/slides/rday_app_slide.jpg) no-repeat center top; height:650px;” >

<img src="/images/slides/rday-app-headline.png” alt=”TIME TO BE LOUDER THEN EVER BEFORE”>
test again

READ MORE

The slides are 1900 wide.. lol so there isn’t a container area, is that all I’d need to do? Is place a container inside where the content would sit and position that?

thanks

Author’s gravatar author

It all depends. Here is the CSS in my example:

The outer container (#scroller) is 100% and the inner items are only 900px. If you place the text inside those elements it should work correctly as the 900px elements aren’t fluid.

Author’s gravatar

Great idea and tutorial !
I use to work with the jQuery library but I never thought to create a entire slider , your idea is simple and effective, congrats !

Reply
Author’s gravatar author

Thanks Jon, glad you liked it & that it was helpful. 🙂

Author’s gravatar

Brilliant. Very easy to impletemtn!
Thanks a million. Perfect explanation!
Good work!

Reply
Author’s gravatar

Hello !

Thanks for this explanation !
I’ve a little problem at the Jquery, and you too.

When you are at the last picture and when you click on the first picture link into nav, the first picture stay just a little moment and not this moment : interval: 10000.

Do you have a patch for the jQuery ?

Thanks
Max

Reply
Author’s gravatar author

That is actually the jQuery Tools plugin that does that. It seems it doesn’t reset the interval when you click one of the navigation pips.

Unfortunately there is no patch available, but if the new version of jQuery Tools is ever released it may have been fixed.

Author’s gravatar

Hey!

I would like to know if it’s possible to make fade transition with full width slider, because i’ve searched on many site but i found nothing…

I would like the same slider but with fade transition. Where i can find it ? Or how make it ?

Thanks !

Reply
Author’s gravatar author

There is a tutorial for a slider similar to this one, but using jQuery Cycle. That is full width & fades instead of sliding. You can find it here.

Author’s gravatar

Excellent tutorial and great helps us to make horizantal scroll

Reply
Author’s gravatar

how to remove left & right line of each image and how do i stretch the image is full width of container?

Reply
Author’s gravatar author

Hi Sethu,

I’m not sure what you mean by ‘left & right line of each image’?

How do you stretch the image? Well, this tutorial is aimed at making it look as if the image stretches the full width by making the background match the image. However if you want the image to stretch to the full width you would have to give the class affecting you image a width of 100% so that it will stretch to the width of anyone’s browser window.

I do have to say that you need to make sure your image is large enough to cope as I have a 1920×1080 resolution screen and some website’s I’ve seen use a stretched image look awful due to the lack of resolution in the image.

Author’s gravatar

Hello all, I’ve got a question. Has anyone noticed all the images flash on the screen briefly as the site’s are loading?

Is there a way to hide them, and using a “loading” .gif or something so that it’s not just a blank screen, and then the images all show.

I’m using images as large as 1900 wide, anyone have any suggestions on getting these file sizes under 150mb

for example:

http://bit.ly/ql4GvV

Reply
Author’s gravatar author

Hi Andre,

150Mb for an image, even 1900px wide, is quite large. Are you using a web compressed jpg? Have you tried something like smushit?

As for the flash, you’ll want to make sure you have overflow hidden on the very outer container that holds the slider, in my case that would be the #scroller element.

If you want a loader, you could try using the onBeforeSeek event in the API. I’m not sure if it would work, but you could hide the element with the scroller in have a loader be in it’s place, then in the onBeforeSeek event have it remove the loader & reveal the scroller… I’m really not sure if it would work, but you can only but try & see what happens. 😉

Author’s gravatar

Hey thanks, Paul however, it is overflow hidden on #scroller and on .slide-wrapper.

I’m no expert with js, learning a lot, lot to learn. 🙂

onBeforeSeek sounds interesting, how’d you get your slides not to flash like that? Could this be a js conflict with another file?

Reply
Author’s gravatar author

Hi Andre,

Not sure what you mean by .slide-wrapper as I don’t have an element with that class in my examples?

I don’t think anyone ever stops learning JS. 😉

I think they may load that quick simply because the images are optimized so they are loaded extremely quickly. The overflow should stop the stacking flash (where the images stack down the page).

Other than images that load extremely quickly, and making it so your page loads enough to trigger DOM ready as soon as possible, there isn’t much you can do other than setting the slider to be invisible until it’s loaded completely.

Older Comments

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.

I'll keep your WordPress site up-to-date and working to its best.

Find out more