Sign In Start Free Trial
Account

Add to playlist

Create a Playlist

Modal Close icon
You need to login to use this feature.
  • Book Overview & Buying Bootstrap Site Blueprints
  • Table Of Contents Toc
Bootstrap Site Blueprints

Bootstrap Site Blueprints

4.2 (10)
close
close
Bootstrap Site Blueprints

Bootstrap Site Blueprints

4.2 (10)

Overview of this book

Table of Contents (16 chapters)
close
close
Bootstrap Site Blueprints
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
4
Index

Initializing TouchSwipe


With just a few lines, we can direct TouchSwipe to detect swipe events on the carousel and translate them into the Bootstrap methods: .carousel('prev') and .carousel('next'). See these methods referenced in the Bootstrap documentation at http://getbootstrap.com/javascript/#carousel.

If you'd like to, you may also consult the TouchSwipe documentation at http://labs.rampinteractive.co.uk/touchSwipe.

Our present task is very straightforward, as shown in the following steps:

  1. In your project files, open main.js in the js folder

  2. Add the following lines of code in the opened file:

    //Enable swiping...
    $(".carousel-inner").swipe( {
      //Generic swipe handler for all directions
      swipeRight:function(event, direction, distance, duration, fingerCount) {
        $(this).parent().carousel('prev');
      },
      swipeLeft: function() {
        $(this).parent().carousel('next');
      },
      //Default is 75px, set to 0 so any distance triggers swipe
      threshold:0
    });
  3. Save the file.

Now, if you test these files on a touch device, you should be able to swipe left to go to the next slide and right to go to the previous one.

That's it. It's a small cost with a clear usability gain.

Congratulations! Your Bootstrap carousel is now swipe enabled.

CONTINUE READING
83
Tech Concepts
36
Programming languages
73
Tech Tools
Icon Unlimited access to the largest independent learning library in tech of over 8,000 expert-authored tech books and videos.
Icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Icon 50+ new titles added per month and exclusive early access to books as they are being written.
Bootstrap Site Blueprints
notes
bookmark Notes and Bookmarks search Search in title playlist Add to playlist download Download options font-size Font size

Change the font size

margin-width Margin width

Change margin width

day-mode Day/Sepia/Night Modes

Change background colour

Close icon Search
Country selected

Close icon Your notes and bookmarks

Confirmation

Modal Close icon
claim successful

Buy this book with your credits?

Modal Close icon
Are you sure you want to buy this book with one of your credits?
Close
YES, BUY

Submit Your Feedback

Modal Close icon
Modal Close icon
Modal Close icon