Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Responsive Media in HTML5

You're reading from   Responsive Media in HTML5 Learn effective administration of responsive media within your website or CMS system using practical techniques

Arrow left icon
Product type Paperback
Published in Dec 2014
Publisher
ISBN-13 9781849696968
Length 128 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
Alex Libby Alex Libby
Author Profile Icon Alex Libby
Alex Libby
Arrow right icon
View More author details
Toc

Table of Contents (7) Chapters Close

Preface 1. Working with Responsive Images FREE CHAPTER 2. Adding Responsive Video Content 3. Mixing Content 4. Testing Responsive Media 5. Using Frameworks Index

Building a responsive carousel

So far we've covered a lot of different techniques to help us produce responsive content. Most of it has been simple examples in a development context. It's time to take a look at a couple of examples of real-world applications where responsive functionality has been put to good use. Our first example is in the form of a responsive carousel. There are dozens of example libraries online that can be used to create one, so there is no need to build from scratch!

Let's take a look at one of my favorites—ResponsiveSlides.js; it's a simple library that provides a useful solution, but doesn't try to achieve everything. We'll borrow one of their examples to see how it works.

  1. As always, we need to start somewhere. Let's begin by downloading the ResponsiveSlides library from http://responsiveslides.com/; the current version is 1.5.4 at the time of writing. Save this in the js subfolder of our project folder.
  2. We also need the styling file for ResponsiveSlides, along with a copy of the jQuery library. Extract a copy of carousel.css, saving it in the css subfolder of our project folder; then do the same for jQuery in the js subfolder.

    Note

    The ResponsiveSlides package comes with jQuery 1.8.3; I've tested it with Version 2.1.1 of jQuery with no apparent ill effects.

  3. Next, extract a copy of carousel.html from the code download that accompanies this book; add the following code between the empty <script> tags immediately below the link to the responsiveslides.js library:
    <script>
      $(function () {
        $("#slides1").responsiveSlides({ auto: false, pagination: true, nav: true, fade: 500, maxwidth: 800
        });
      });
    <script>
  4. Save the file. If we preview the results in a browser, we will see our carousel appear.
    Building a responsive carousel
  5. Try resizing the browser window now. We should see the carousel reduce in size but continue to scroll through the images with no loss of quality.

There are plenty of examples of responsive carousels available online—two such examples are WOW Slider at http://wowslider.com/, with an example of what is possible at http://www.wowslider.com/responsive-image-gallery-glass-collage.html, Owl Carousel (http://www.owlgraphic.com/owlcarousel) and BXSlider, available at http://bxslider.com/. It is a matter of trying a selection and choosing the one that suits your requirements.

Note

There is a prebuilt working example on the code download that accompanies this book. Extract copies of carousel-finished.html and carousel-finished.css, then rename them to carousel.html and carousel.css. You will need to extract the accompanying libraries, as outlined in this exercise, for it to operate correctly.

You have been reading a chapter from
Responsive Media in HTML5
Published in: Dec 2014
Publisher:
ISBN-13: 9781849696968
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime