How to Start Using jQuery Sliders in Your Designs
basix

How to Start Using jQuery Sliders in Your Designs

Tutorial Details
  • Requirements: A web browser
  • Difficulty: Easy
  • Time to Complete: 15-30 minutes

jQuery sliders offer a simple, elegant way to display content without giving up valuable real estate on your web page. They have skyrocketed in popularity and can be used in a variety of ways. Let’s go over the popular styles, choosing a slider and integrating one into a demo site.


A Little Background

Once upon the time, an image on the web just had one way of showing up: as a flat JPG, GIF or PNG. Sometime a few years ago, images started learning new tricks; They grouped together and started showing up in jQuery sliders to the applause of visitors all around.

Since then, they’ve learned a plethora of new tricks that make them prime material for any web designer. Whether you’ve used them before or not, this tutorial will give you insight into the different flavors of sliders, when to use them in a design, and we’ll even walk you through an installation of one.

If there is one thing jQuery sliders don’t have, it’s a consistent name. The slider goes by a wide array of aliases: gallery, carousel, promos and rotators but they all provide the same general feature – display multiple content items in a shared space on the page. For the purpose of this article, I will refer to them all as a “slider”.

jQuery sliders can be used for nearly anything but most are used display a number of photos in a slideshow format in a way formerly handled by Adobe Flash. Many offer a number of transition effects between slides and can be controlled by previous/next buttons, tabbed or thumbnail navigation.


Popular Styles of jQuery Sliders

The number and variety of sliders continues to grow steadily, so finding a slider to fit your needs has never been easier. They come in all shapes, sizes, and sizes – a number of them are free, which means that when you do pay for a slider, it’s usually loaded with great features.

Lets walk through a few of the more popular styles of sliders below. Keep in mind, most examples shown are from the unstyled demo versions and all can be customized with some basic CSS knowledge and reading the documentation.

Standard Photo Slider

jquery photo slider
Example used: NivoSlider – http://nivo.dev7studios.com/

A very popular style of slider is the photo slider. Many accept an image and some metadata such as a caption, often pulled from the alt or title tag automatically.

Advantages: Typically the easiest to get started with for beginners. The focus is put directly on a large image you choose. Many have multiple transition effects between slides from sliding, fades, zooms and more.

Disadvantages: If you have a wide variety of content you need to display such as HTML, images or video, a mixed content slider may be a better choice – most require you to stick to images.


Mixed Content Slider

jquery mixed contentslider
Example used: Anything Slider – http://github.com/chriscoyier/AnythingSlider

While similar to the photo slider, mixed content sliders allow you to use more than just images. Review all the options when choosing an image slider, some do allow for HTML but may not be listed in the primary feature list.

Advantages: Perfect for displaying video, HTML and image content within the same slider if needed.

Disadvantages: Mixed content sliders can be a bit more advanced to work with than your standard photo slider.


Gallery Style Slider

jquery gallery slider
Example used: Galleria – http://devkick.com/lab/galleria/

The gallery style is often used in photography applications. The navigation is often made up of thumbnails to browse through the images in your collection.

Advantages: Very easy for users to browse through the images they want to see quickly.

Disadvantages: Often times takes up more real estate on the page than a standard slider to fit the image and all thumbnails.


3D Block Slider

3d Block slider Cu3er cuber
Example used: Cu3er – http://getcu3er.com/

Think of a Rubik’s cube, built on the web, without all the headaches. That’s basically what a 3D Block Slider is – it’s incredibly impressive from a visual standpoint, and can be perfect to add that extra bit of excitement to a site.

Advantages: One of the most visually stunning sliders out there. If visitors haven’t seen it before, their jaws might hit the floor.

Disadvantages: While the rest of the sliders in this tutorial are jQuery, most of the 3D Block Sliders are built in a combination of Adobe Flash and XML… which isn’t the most “standards friendly” format to use. These sliders can require a little more time to “preload”; Because they are built with Flash, it also means that they can be a little trickier to install if you aren’t familiar with it.


3D Space Slider

Inspired by Apple’s cover flow effect, this slider effect is a stunning way to display your work. When coupled with a minimal style site, this slider can feel right at home.

Advantages: This style can be a very impressive and very interactive way for users to browse a gallery of images showcasing your work.

Disadvantages: Many have a small scroll bar or use the mouse scroll wheel or keyboard to view the images which can be a bit awkward with some unintentional scrolling.


Full Size Slider

The full size slider is what it seems – a slider that takes up the entire page to show off your work in a way that can’t be missed.

Advantages: If you have a “go big or go home” style, they really do not get much bigger than this.

Disadvantages: They may be a bit tough to integrate into a site since they are designed to fill the screen with your work. Images used must be quite large to fill new high resolution screens.


Thumbnail Slider

jquery thumbnail slider
Example used: jCarousel Lite – http://www.gmarwaha.com/jquery/jcarousellite/

Sometimes you may find yourself in a situation where you want to display a grid of images and allow quick browsing without making the user load a second or third page.

Some sliders have the capability to show multiple images per slide or multiple slides at once so check the feature list. In jCarousel Lite featured above, “visible” is set to 3, showing three slides at a time.

Advantages: Allows you to scroll multiple items at once for times when a large image or content is not needed. Great for groups of items or when you have the room on the site.

Disadvantages: There are not many disadvantages to this style other than just being a little more complex to set up than the standard photo slider.


Horizontal Sliding Tabs / Accordion Slider

jquery accordion tabs slider
Example slider used: HSlides – http://plugins.jquery.com/project/hslides
Sample image is from the Circo theme: http://bannersmonster.com/themes/Circo/

The accordion style makes browsing through featured items a little like flipping through pages of a book. This uses a classic “hide and reveal” user behavior by just showing a snippet of the content before sliding the entire accordion box out.

Advantages: A very unique and fun way to display your items. The stepped style can help reinforce a sense of order if you are using a “step 1, step 2, step 3″ content paradigm.

Disadvantages: Not great for dozens of slides and can be a bit difficult for new web users to operate accidentally sliding items open and close with a pass of the mouse. Consider a click to open tab style or setting if available.


Large Tabbed Slider

jquery large tabbed slider
Example used: Feature List – http://jqueryglobe.com/article/feature-list

The feel you get when using the large tabbed slider is a sense of simplicity – step 1, step 2, step 3. A great way to show progressive changes, features or product options.

Advantages: Very attention grabbing with proper styling. Like the accordion, this slider shows a hint of what is inside each slide, which can be great for visitors that are seeking specific information.

Disadvantages: You may need to limit the number of items you want to include unless you use a tabbed slider like the iTunes Music Store.


When to Design Your Own Slider

Although the variety and quantity of sliders is steadily on the increase, sometimes you just can’t find a solution for for your unique situation.

If you are going to be using many sliders in your projects, it is worth your while to dig in and really learn how they work and build one yourself. The best way to learn is by example.

Dissect existing sliders, see how they work and learn from it. Don’t steal other developer’s code but instead focus on what they are doing: animations, changing opacity and reviewing the settings they offer and write it in your own way.

With tools like Firebug, you can “inspect” a slider in real-time, watching it manipulate the z-index, opacity or positioning to move content from one slide to the next.

You will gain a greater understanding of what is going on under the hood, be able to perform customizations, and find problems faster down the road by digging into as many sliders as you can to learn how they function.


Finding The Right jQuery Slider for You

The only thing more plentiful then the number of jQuery sliders are the number of sites showcasing them. Rather than try to list all of them here (new ones come out every week!), let’s walk through how to find one that’s right for you:

A quick Google search will reveal sliders can be found in a variety of places:

Roundup Posts

Often titled something like “25 Useful jQuery Content Slider Scripts” – they are posts created to collect and review the different sliders available at the time. Read the comments as well as the article to see other people’s opinions on the collection.

Tutorial Sites

Sites that offer up tutorials on building sliders will often times include the final source code of the project so you get a step-by-step guide as to how it is built and the final working result. Unless specifically noted, the source project is just for educational purposes, ask before using in any projects.

Online Marketplaces

CodeCanyon offers an entire category for premium sliders. http://codecanyon.net/category/javascript/sliders

View-Source

Sometimes you will come across a site with a slider and you want to see which plugin they may have used. Since JavaScript is a client-side script, do a view-source of the page and look which JavaScript files are imported, the plugin information should be included at the top of the plugin’s source script with a URL for more information on the plugin for download and documentation.

Be courteous of the effort others have done, read and abide by the license agreements included and give credit where credit is due.


Deciding on a Slider

Choosing a slider is largely dependent on the functionality and options you need and the overall style you are going for. Decide on the type of content you need displayed, how you want users to navigate through it and see which slider best matches your requirements.

Once you have narrowed down your choices, compare the overall script size and check whether is is compatible with all browsers.

Some sliders are offered in a “lite” version such as jQuery Cycle Lite if you’re looking to keep the overall file size down in your project. Often times, the light version is just missing the additional transition effects, sticking with the most popular options available.

If you’re not a jQuery master, choose a slider with great live demos you can download and documentation to help guide you through making your customizations.


Skinning a Slider

One of the great things about using a pre-made slider is that most of them are incredibly easy to redesign according to your needs. This process (usually just called “skinning”) isn’t as hard as it might seem. Usually it requires just editing a simple CSS file – the most complex skinning will usually get is swapping out graphics that you’ve created their the default graphics (like backgrounds and buttons).

In addition to skinning sliders, it’s also worth noting that with most sliders, it’s easy to change the size to fit the website that you’re designing.


Integrating Sliders with an Existing Site

Placing a slider in an existing design is not a single-step process but most slider scripts come with a basic sample page to get started, importing jQuery, CSS, sample content and initializing the plugin with the default settings.

Let’s import jQuery Cycle into a quick sample site created for the purpose of this tutorial.

Download the before and after sites to follow along.


1. Initial Site Structure

The demo site consists of basic HTML, CSS and an image which will be the starting point for integrating the slider.

  • index.html – The sample home page we are using
  • css/screen.css – General style information
  • images/sample_water.jpg – Current static image for the home page

2. Download jQuery Cycle

We will be integrating the jQuery Cycle plugin for this demo.

  • Visit http://jquery.malsup.com/cycle/
  • Download and unzip the latest version to your computer.
  • Copy jquery.cycle.all.min.js to your site in a new /js/ directory

3. Import the Necessary Scripts

Import the jQuery library and the Cycle plugin in the of your site by adding this code:

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript" src="js/jquery.cycle.all.min.js"></script>

The first script should be the latest version of jQuery. You can grab it off jquery.com or load it from the Google Libraries as we have done above.

The second script is the plugin source which we placed in the /js/ folder.


4. Add the Slider HTML

Swap out the current static sample_water.jpg image used in the demo site with an unordered list for slides:

<ul id="promo">
    <li><img src="images/sample_water.jpg" alt="Slide One" /></li>
    <li><img src="images/sample_hills.jpg" alt="Slide Two" /></li>
    <li><img src="images/sample_park.jpg" alt="Slide Three" /></li>
</ul>

We will just use three images to get started, note the id=”promo” attribute, we’ll use this later to tell our plugin this is the container of our slides. Since the slides are essentially just a list of related content, a UL tag is a good choice.


5. Add the Optional Slider Navigation

Underneath the unordered list of promos we added above, we will add the navigation to control the slides. The plugin will create the individual navigation links dynamically at runtime as you add and remove slides from the list.

 <div id="promonav">
    <a href="javascript:void(0);" class="next">Next Slide</a>
    <div id="promoindex"></div>
</div> 

The next slide button’s class corresponds to the ‘next’ parameter we will use to advance the slides manually.

The promo index is automatically generated if the ‘pager’ parameter is set in the options. By entering it manually, we can control where it goes on the page in case you wanted it somewhere other than where the plugin places it.


6. Style the Slider

Let’s add CSS to style the slider list. Some sliders like Nivo Slider have a custom stylesheet you can download and get started but for this demo, let’s add our custom CSS directly into the end of the site’s main screen.css file.

/* Remove list formatting from Promo UL/LI */
#promo, #promo li
{
    margin:0;
    padding:0;
    list-style-type:none;
}
/* Styles for the optional promo navigation container */
#promonav
{
    padding:4px;
    background:#eee;
    border:1px solid #e0e0e0;
    margin-top:1px;
}
/* Keep the next button at the right edge */
#promonav .next
{
    float:right;
}
/* Link styles in promo navigation  */
#promonav a
{
    padding:0 3px;
    border:1px solid #eee;
    text-decoration:none;
    outline:0;
    color:#777;
}
/* Style applied on mouseover of promo navigation link(s) */
#promonav a:hover
{
    color:#000;
}
/* The index automatically gets an activeSlide class, use this to indicate the current slide */
#promoindex a.activeSlide
{
    font-weight:bold;
    background:#fff;
    border-color:#ccc;
}

7. Initialize the Plugin:

At this point, we have jQuery and the plugin imported but nothing telling the plugin which element on the page is our slider or what options to include – it needs to be initialized.

Create a file called setup.js and place it in the /js/ directory.

Import it in underneath the jQuery and Cycle scripts you imported in the area of the site earlier in the tutorial.

<script type="text/javascript" src="js/setup.js"></script>

It is important that you import jQuery, jQuery Cycle and then setup.js in that exact order or the plugin will not work.

Inside setup.js add the following code:

$(document).ready(function() {
    $('#promo').cycle({
        fx: 'scrollHorz',
        timeout:    4000,
        speed:      800,
        next: '#promonav .next',
        pager:    '#promoindex',
        height: 200,
        pause: 1
    });
});

Lets me explain what is going on in the code above.

We start out by checking if the document is ready with the document.ready, otherwise the plugin may try to modify elements on the page that are not available or ready.

The next line is telling the Cycle plugin what element we are using as a container of the items we want to cycle through. In our case, the container has an ID of promo so we enter #promo.

The items listed from fx to pause are options we are passing into the plugin. If we do not include any and simply use: $(‘#promo’).cycle(); the plugin would use its default settings. Options are listed in a comma separated list. The number and type of options vary per-plugin but for jQuery Cycle can be found at http://jquery.malsup.com/cycle/options.html

The next and pager options refer to the navigation we built in step 5 above and can be removed if you do not want to include navigation on the slider.

Download the before and after sites to follow along.


Think Outside the Container

Sliders do not need to be large photo sliders stretching across a page of your site. Use them to display sections of rotating content such as testimonials, your latest tweets or popular blog articles in areas of the site that could benefit from the extra room.

Thanks for reading!

Curt Ziegler is cudazi on Themeforest
Note: Want to add some source code? Type <pre><code> before it and </code></pre> after it. Find out more
  • http://adriandemian.com Adrian Demian

    Very nice collection. Keep up the good work.

  • Alexander Rose

    Thanks Curt, this is great for a newbie like me :-)

  • http://inviadesign.com ivan p.

    nice thanks for the info

  • http://smallbitsofcode.com Boba

    Thanks, great article.

    Also for those who want some cool sliders, check out Orbit Slider and Coin Slider. Orbit is relatively new so you might not have heard about it.

    • http://themeforest.net/user/epicera/portfolio?ref=epicera Brandon Jones

      Thanks for sharing those sliders Boba – both of them look great.

      • http://smallbitsofcode.com Boba

        You’re welcome, i enjoy your articles here, keep it up.

        • pixelBender67

          I just installed the Orbit slider, my favorite, I also like pretty photo, but Orbit is really nice =)

    • Vitor Melo
  • http://edisonmachado.com.br Edison Machado

    Very good, Im loving your new blog! Thanks

  • http://sffarlenn.net/blog/ Laneth Sffarlenn

    This has been something playing on my mind for a while now – thanks for a brilliant roundup / tut / article :)

  • Spencer

    Great roundup, just the links under the images don’t match up. Had to click through a bunch of different ones to find the one I was looking for :)

    • http://themeforest.net/user/epicera/portfolio?ref=epicera Brandon Jones

      Hi Spencer – which ones aren’t working?… They all appear to be matched up properly to me. If you spot a typo I’ll be sure to fix it right away though. Thanks for the note!

      EDIT: Found the mismatched one and patched it up :)

  • http://mywebhostinglab.com reezluv

    now I know there are a lot of jQuery Sliders and will make one for my sites.thanks

  • Zwei

    I thought sliders were made by using Flash.. O.o

    Anyway this info i a really big help..

    thank you so much!

    • http://cloudystudio.com Rasmus

      Zwei some sliders are made using flash like Cu3er which is represented in this post. But javascript is faster as the author also points out. When you put it this way your thoughts about how sliders were made is not wrong but there are different kinds of sliders.

      • http://themeforest.net/user/epicera/portfolio?ref=epicera Brandon Jones

        Yep – it’s hard to have a post about sliders without mentioning other technologies like Flash, but there are definite benefits to using jQuery.

      • http://www.seoexploration.com Fred

        Main downer for flash is that doesn’t work on ipads and iphones. Just been through that loop and returning JS

  • Luca

    mootools, I want mootools.

  • http://oddnetwork.org haliphax

    I believe that jQuery Cycle – http://jquery.malsup.com/cycle/ – can do all of those except for the “3D style” sliders. It’s a really versatile plug-in.

    Good article!

    • http://themeforest.net/user/epicera/portfolio?ref=epicera Brandon Jones

      Thanks for the idea Haliphax!

  • T

    Thanks a lot. Definitely will try this out.

  • http://heathwaller.com/ Heath Waller

    Really nice overview of how to add a slider to your web design. There are some sliders I go to again and again just because I know I can make them work. Like the looped-slider.

    One quick thing, I think the links beneath the “Gallery Style Slider” image are incorrect.

    Thanks for the article.

    • http://themeforest.net/user/epicera/portfolio?ref=epicera Brandon Jones

      Hi Heath – Yep – I just patched the titles – thanks for the note :)

    • http://tbd Jason

      Heath,

      This is the first time we’re in touch regarding Curt Ziegler’s Luxury theme, which I quite like and would like to use. However, what I’ve researched, I still can’t seem to make the slider images work properly.

      I’m willing to compensate you for your time — for an agreed-upon, 1-time hourly rate — via phone or WebEx to help me figure out how to do it.

      Please reply and kindly tell me when we could do this or recommend one of your colleagues who knows how to do so.

      Once more, thank you very much.

      Most cordially, ciao,

      Jason

      [Personal Number Edited Out - Heath, reply if you want me to connect you two :) - Brandon]

  • kyle

    This is exactly what I needed. THANKS!

  • mxl

    Thanks, nice article, never used a JQuery slider but have been seeing them, now is the time.

    Cheers mate.

  • http://www.lucasdelrio.com.ar Lucas del Río

    Finally! I’ve been waiting for a tutorial about sliders so clear and full of variety as this one =) Thanks a lot for this great article, so helpful, must leave to university now but a I feel like staying and giving a try to every single slider case ^^

  • http://www.pixelarama.com Pierre

    Big ups Brandon – another solid article. Great source of information on sliders for all web designers.

    Cheers!

  • Ciwan

    Thank You. This was very helpful

  • http://cudazi.com/ cudazi

    Great to see everyone enjoying the article, for those of you who use sliders already I would be interested in seeing more of your own favorites, anything new you’ve recently discovered and so on – thanks for reading!

    Curt Ziegler

  • http://charmingwp.com Ahmad

    Pretty nice thanks for sharing the idea

  • sarthak

    Great post. Awesome.

  • http://daanweijers.com Daan

    Cu3er is a Flash example, but the title says ‘jQuery sliders’, shouldn’t it just be sliders then?

    ——–

    Nonetheless, a good list with a nice explanation for each example. Keep up the good work!

    • http://themeforest.net/user/epicera/portfolio?ref=epicera Brandon Jones

      Good catch Daan – I initially labeled the title “Content Sliders”, not “jQuery Sliders”, but the latter made more sense since all but one are jQuery. To be fair, Curt left Cu3er out of the draft that he turned in to me, but I added Cu3er last minute to expand the discussion – so the title inaccuracy is on me :) Either way, glad you liked the article!

  • http://www.clickis.eu Office

    Really nice slider collection, thanks for the post.

  • http://active.tutsplus.com Ian Yates

    Great article! Barely a website hits the net these days without some form of content/image slideshow!

    I’m going to cheekily take this opportunity to mention the Piecemaker Gallery over on Activetuts+. It’s a fantastically flexible (and free) alternative to the CU3er slideshow. Feel free to check it out!

  • http://www.twentyeleven.co.uk Nigel

    Awesome, exactly what I was looking for. Thanks Cudazi

  • http://www.jacdaw.co.uk JacDaw

    Nice!!

  • Jb

    You can add a swipe effect for iOS devices pretty easily on these sliders (especially on AnythingSlider):
    http://jbernus.com/blog/add-swipe-effect-to-anythingslider/

  • Pingback: Best of Tuts+ – October 2010

  • Pingback: 使用jQuery设计slideshow | Design lol 全球设计精华分享

  • Pingback: Dagens länkar erikgmpantzar

  • http://www.ymart24.com riyad

    as usual…just read the tutorial.. its really very helpful for those who are at beginner level. really enjoyed this article.


    Riyad

  • http://tasarhane.com tasarhane

    helpful.. thanks

  • Ali

    Brandon! can we use more than one slider on single page?

    please reply.. thanks

    • pixelBender67

      Yes you can, you can do what ever you would like as long as you know what you are doing and want
      you can have as many as you want, why ?

      • Ali

        I need to make that particular page as entry point of my two different websites. If i can do then please give me an idea. thanks….

  • Sarunas Savickas

    Something new for me. Thanks boba.

  • Pingback: A nice way to beef up your website: add JavaScript Sliders & Slide Shows « Web Yodel Blog

  • http://creativelanka.com web design sri lanka

    Awesome work thanks for sharing. This was really nice slider collection, Keep it up.

  • Pingback: Sliders jQuery en tus diseños

  • http://51websitedesign.com 51 Website Design

    jQuery actually IS easy lol. I’m so excited about how front end web development will be for me in the future :D:D.

  • Pingback: 20+ Awesome Jquery Slider Tutorials | Tutorials Share | Tutorials, Resources & Tips for Designers!

  • sect

    Thanks for the post. A bit of proof reading would have been helpful :)

  • Pingback: My Stream » Best of Tuts+ – October

  • Pingback: Slideshows jQuery en tus diseños | JuanjoFR

  • http://www/strategiccreative.com.au Dani

    This is a great article, thank you. I am actually looking for a slider that will run three images at a time, each with three separate links like this example: http://www.rachaelgoldsworthy.com.au/

    Does anyone seen where I can get this?

    Thanks so much

  • Smart eDesigners

    ah… very nice collection.

  • Pingback: Best of Tuts+ in October | Envato Notes