How To: Recreate the Apple Product Slider with JQuery

slider

Stylishly capitalize on limited space with a side scrolling image gallery, similar to the one that Apple uses to show off their products.

What is it?

The product slider is a cool way to show off something like an image gallery in a limited amount of space. You can use it for an e-commerce inventory solution or to show off photos from a recent vacation.

It’s a simple task for JQuery UI. While you won’t be using much, it does require the jquery.dimensions, ui.mouse, and the ui.slider components. Use this code snippet in the head section of your markup to take care of it.

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

<script src="jquery.dimensions.js" type="text/javascript"></script>
<script src="ui.mouse.js" type="text/javascript"></script>
<script src="ui.slider.js" type="text/javascript"></script>

The Markup
The HTML consists of an unordered list of items for the gallery, with labels for the slider appearing further below in the span.

<div class="sliderGallery">
  <ul class="items">
    <li>Item one</li>
    <li>Item two</li>
    <li>Item three, etc...</li>
  </ul>
  <div class="slider">
    <!-- the handler to action the slide -->
    <div class="handle"></div>
    <!-- labels appear against the slider, as pointers to the user -->
    <span class="slider-lb1">slider label 1</span>
    <span class="slider-lb2">slider label 2</span>
    <span class="slider-lb3">slider label 3</span>
  </div>
</div>

The Stylesheet

.sliderGallery {
    overflow: hidden;
    position: relative;
    padding: 10px;
    height: 160px;
    width: 960px;
}
.sliderGallery UL {
    position: absolute;
    list-style: none;
    overflow: none;
    white-space: nowrap;
    padding: 0;
    margin: 0;
}

.sliderGallery UL LI {
    display: inline;
}

.handle {
    position: absolute;
    cursor: move;
    top: 0;
    z-index: 100;
    /* bespoke to your own solution */
    height: 17px;
    width: 181px;
}

The JQuery

$(window).ready(function () {
  $('div.sliderGallery').each(function () {
    var ul = $('ul', this);
    var productWidth = ul.innerWidth() - $(this).outerWidth();

    var slider = $('.slider', this).slider({
      handle: '.handle',
      minValue: 0,
      maxValue: productWidth,
      slide: function (ev, ui) {
        ul.css('left', '-' + ui.value + 'px');
      },
      stop: function (ev, ui) {
        ul.animate({ 'left' : '-' + ui.value + 'px' }, 500, 'linear');
      }
    });
  });
});

…and that will do it for you.

If you found this tutorial useful, don’t forget to subscribe to the Cherrysave RSS feed. Or, you can follow me on Twitter.

@simplrdesgn: RT 10 Web Design Blogs You Should Be Reading
Want more? Follow me on Twitter!

7 Comments

  1. Posted September 5, 2009 at 5:08 am | Permalink

    Great work. Thx

  2. Posted September 6, 2009 at 1:46 am | Permalink

    no demo?

  3. Colin
    Posted December 9, 2009 at 3:42 pm | Permalink

    No demo?

  4. aqua
    Posted January 22, 2010 at 3:13 am | Permalink

    I tried this however it did not work. I don’t know why.

    http://liamdye.ca/PortfolioTest.html

  5. aqua
    Posted January 22, 2010 at 3:15 am | Permalink

    By the way, in an attempt to make it work I added the overflow scroll in .sliderGallery

  6. Ian
    Posted February 7, 2010 at 4:29 am | Permalink

    While I hate to bash someone’s efforts to help others, reading through this page makes me wonder how much you actually thought about the kind of people you presumably wrote it for.
    For one, no demo page!? This is the single biggest bugbear I see regularly on tutorial pages; why go to the trouble of writing a tutorial unless you’re going to provide a working demo for people to check their code against? How do I know your tutorial even works?
    Second, you’re very vague and assuming about which version of jQuery and jQueryUI that this is supposed to work with, and also about how people go about getting the necessary components of jQueryUI. You *do* know that the jQueryUI website doesn’t let you download individual components, right? There aren’t even any components called “dimensions”, “mouse” or “slider” on the download page for you to select. How is the average user (and again, presumably your target audience for this tutorial?) expected to know how to extract these 3 individual components? There’s already one nice-looking Apple-style product gallery script out there that only works with obsolete jQuery components, whose author seems uninterested in getting it to work with the current release. Let’s not have this one suffer the same fate, eh?

  7. Ian
    Posted February 7, 2010 at 4:45 am | Permalink

    Actually, scratch everything I just said. I just checked the page on jqueryfordesigners.com and your “tutorial” is nothing of the sort. You just took Remy’s code and posted it here without any credit to him.
    Kind of explains a lot.

13 Trackbacks

  1. How To: Recreate the Apple Product Slider with JQuery…

    Stylishly capitalize on limited space with a side scrolling image gallery, similar to the one that Apple uses to show off their products.

  2. [...] Create an Apple-style Product Slider with JQuery [...]

  3. [...] Sitio: http://www.cherrysave.com/web-design/how-to-recreate-the-apple-product-slider-with-jquery [...]

  4. [...] How To: Recreate the Apple Product Slider with JQuery Categorías:interfaz, jQuery Etiquetas:jQuery, slider Comentarios (0) Trackbacks (0) Deja [...]

  5. By links for 2009-09-17 | Digital Rehab on September 17, 2009 at 8:34 pm

    [...] Create an Apple-style Product Slider with JQuery – Cherrysave (tags: jquery slider apple tutorial javascript gallery design code) [...]

  6. [...] Recreate the Apple Product Slider Un tutorial pour obtenir un slider dynamique comme sur le site d’Apple. [...]

  7. [...] Ah, Apple website. Since their latest redesign, this site is often quoted by many blogs as being a must-see in terms of design and usuability. With this tutorial, you’ll be able to reproduce Apple products slider, using jQuery. » View tutorial [...]

  8. [...] Recreate the Apple Product Slider with JQuery アップルの製品案内風のナビゲーション [...]

  9. [...] » Ver Tutorial [...]

  10. [...] Ah, Apple website. Since their latest redesign, this site is often quoted by many blogs as being a must-see in terms of design and usuability. With this tutorial, you’ll be able to reproduce Apple products slider, using jQuery. » View tutorial [...]

  11. [...] 10. How To: Recreate the Apple Product Slider with JQuery [...]

  12. By 10 Técnicas JQuery para maximizar tu Sitio Web on January 5, 2010 at 12:41 pm

    [...] En Apple se ve un slider de todo su hardware, aquí nos proponen como hacer algo parecido. Ver turtorial >> [...]

  13. By 15个Apple设计风格代码指南 | 知更鸟 on February 6, 2010 at 12:33 am

    [...] 10. How To: Recreate the Apple Product Slider with jQuery [...]

Post a Comment

Your email is never shared. Required fields are marked *

*
*