Coder Social home page Coder Social logo

swipeshow's Introduction

Swipeshow

The unassuming touch-enabled JavaScript slideshow. Requires jQuery 1.8.

  • Showcase anything. You're not limited to images: any markup will do.
  • Touch-enabled. Swipe away on your iPad, iPhone, Android device, or anything touch-enabled.
  • Style-it-yourself. The default CSS has nothing in it except laying out your slides side-by-side. You'd be in charge of figuring out how to add borders or anything else you like.
  • Hardware-accelerated. Animations are done via CSS transitions, which will render smoothly on mobile devices. It will automatically fall back to frame-by-frame animation when transitions aren't available.

More features!

  • Auto-pauses on hover
  • Percent-based width slideshows are supported
  • Graceful degradation (shows slide #1 when JS isn't available)
  • Auto-advance can be turned on/off (autostart)
  • Configurable, like... totally
  • Can be controlled via JavaScript

How to use

How to use

Follow the HTML markup guide (see below), then use the sample CSS (also listed below). Then just fire $('...').swipeshow().

HTML markup

Simply create an element that includes the class swipeshow and contains some slides.

Swipeshow goes by the assumption that your slideshow element looks like .slides > .slide. You are free to put other elements inside .slide or .swipeshow.

<div class="my-gallery swipeshow">
  <ul class="slides">
    <li class="slide"> ... </li>
    <li class="slide"> ... </li>
    <li class="slide"> ... </li>
  </ul>
</div>

In this example, we used the class my-gallery swipeshow: where my-gallery is a unique name we gave our slideshow so we can style it later.

CSS

Define the dimensions of your slideshow. For responsive layouts, you may also use percent-based widths (width: 100%).

.my-gallery {
  width: 200px;
  height: 200px; }

JavaScript

...and that's it!

<link rel='stylesheet' href='jquery.swipeshow.css'>
<script src='jquery.swipeshow.js'></script>
$(function() {
  $(".my-gallery").swipeshow();
});

Options

All these options are optional.

$(".my-gallery").swipeshow({
  autostart: true,    /* Set to `false` to keep it steady */
  interval: 3000,     /* Time between switching slides (ms) */
  initial: 0,         /* First slide's index */
  speed: 700,         /* Animation speed (ms) */
  friction: 0.3,      /* Bounce-back behavior; use `0` to disable */
  mouse: true,        /* enable mouse dragging controls */
  keys: true,         /* enable left/right keyboard keys */

  onactivate: function(){},
  onpause: function(){},
});

The onactivate hook is called when you first initialize swipeshow, and again each time a swipe event occurs. The method receives the following arguments:

  • current slide (DOM object)
  • current slide index
  • previous slide (DOM object)
  • previous slide index

Next/previous buttons

Add some buttons with the class .next and .previous inside .swipeshow. They will work as expected. (style them yourself)

<div class="my-gallery swipeshow">
  <ul class="slides">
    <li class="slide"> ... </li>
    <li class="slide"> ... </li>
    <li class="slide"> ... </li>
  </ul>

  <!-- optional controls: -->
  <button class="next"></button>
  <button class="previous"></button>
</div>

If you prefer them to be elsewhere, you can pass them as jQuery objects to the options:

$(".my-gallery").swipeshow({
  $next: $("button.next"),
  $previous: $("button.previous")
});

Dots

To have dots, simply have a .dots container after the .slides:

<div class="my-gallery swipeshow">
  <ul class="slides">
    <li class="slide"> ... </il>
    <li class="slide"> ... </li>
    <li class="slide"> ... </li>
  </ul>

  <!-- optional controls: -->
  <div class='dots'></div>
</div>

They will be populated like so:

<div class='dots active'></div>
  <button class='dot-item'><span class='dot' data-number='1'></button>
  <button class='dot-item'><span class='dot' data-number='2'></button>
  <button class='dot-item active'><span class='dot' data-number='3'></button>
</div>

If you would prefer them to be elsewhere in your markup, just pass an object to $dots in the options:

$(".my-gallery").swipeshow({
  $dots: $("div.dots")
});

Controlling the slideshow

Access them using $(".my-gallery").swipeshow():

$(".my-gallery").swipeshow().next();
$(".my-gallery").swipeshow().previous();
$(".my-gallery").swipeshow().goTo(2);

$(".my-gallery").swipeshow().pause();
$(".my-gallery").swipeshow().start();

Magic classes

Your markup gets additional CSS classes depending on things. This allows you to style more stuff via CSS.

  • .swipeshow
    • has the touch class when touch is on, or no-touch on desktops.
    • has running when the slideshow is auto-advancing.
    • has paused when the slideshow is paused (like on hover).
    • has swipeshow-active after Swipeshow is initialized.
  • .slides
    • has the gliding class when it's gliding.
    • has the grabbed class when it's currently being dragged.
  • .slide
    • has the active class when it's the selected one.
  • <html>
    • has the swipeshow-grabbed class when grabbing a slide.

Unbinding Swipeshow

You can destroy a Swipeshow by doing:

$(".my-gallery").unswipeshow();

This is different from .swipeshow().pause() in that it unbinds all events and destroys any trace of there ever been a slideshow.

This is useful if you want to, say, re-initialize the slideshow with new items (since you can't change items while a slideshow is happening).

Cycler

Need more control over your slideshow? Use Cycler.js: a very simple library for doing slideshow animations. It is bundled with swipeshow, and is also available separately.

It lets you define all behavior yourself and just provides you a model-like interface to manage the slides and timers.

Alternatives

You may also want to try other libraries. These libraries also support touch, swipe, and mobile-friendly transitions:

Limitations

Some known limitations:

  • It's assumed that the length of slides are fixed. You can't add or remove new slides while a slideshow is running.

To get around these limitations, you can always destroy a swipeshow by using .unswipeshow() and re-initializing it.

Also:

  • Only horizontal scrolling is supported. (Seriously, a vertical slideshow is silly)

License

MIT

swipeshow's People

Contributors

billymoon avatar iankpconcentricsky avatar marksteve avatar mikefowler avatar milesmatthias avatar rstacruz avatar tamdao avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

swipeshow's Issues

On click go to next slide

I would like to add a very simple feature that a lot of galleries have: that when I click on an image that it goes to the next slide.
When I set the $next to the whole slideshow I can click on it to get to the next slide. But unfortunately click gets also called when I swipe or drag which results in in a double next. Is there any trick that I could prevent this behavior?

Support for vertical sliders

It would be nice to have the option to swipe up and down to do the same thing that currently works for left and right.

doesn't allow vertical scrolling of long content

I'm using your plugin to have the entire page be swipable, but when the page is viewed on a smaller window or device and the content in the slide gets too long, I can't vertically scroll.

Is there a fix for this I'm overlooking? Considering switching to a different plugin for this reason.

"counter" that shows current image-index and total index

Trying to figure out how to use "onactivate" to update an element with the current index-number and also fetch the total index. Is this possible or do you need to add something to the code?

Like:
onactivate: function() {
document.getElementById("slide-counter").innerHTML = index + " / " + index_total;
}

pause on hover glitchy

On 1 machine (out of 3) tested, in chrome, the auto pause on hover does not pause the presentation
Windows 7, most current version of chrome browser

any thoughts?

Multiple sliders on a page?

Hi,

what would be the best way to have multiple sliders on a page with individual controls (prev, next, dots navigation, auto slides, even captions)?

If i have two or more sliders on a page, the prev and next buttons triggers all of the sliders.

Thanks in advance :)

Touch swipe not functioning in iOS (iPhone, iPad) - with fix

Touch swiping is working fine in Android, Windows Phone, and desktop (with mouse or touch), but the images are not being switched or animated on iOS devices (iOS 8+). Looking at your code, I found another -webkit- needed to be added in the setOffset function so mobile Safari can properly transform.

Current code (line 571):

function setOffset($el, left, speed) {
    $el.data('swipeshow:left', left);
    if (transitions) {
      if (speed === 0) {
        $el.css({ transform: translate(left, 0), transition: 'none' });
      } else {
        $el.css({ transform: translate(left, 0), transition: 'all '+speed+'ms ease' });
      }
    } else {
      if (speed === 0) {
        $el.css({left: left});
      } else {
        $el.animate({left: left}, speed);
      }
    } 

Fixed for iOS device (if (transitions) statement):

    if (transitions) {
          if (speed === 0) {
            $el.css({ transform: translate(left, 0), "-webkit-transform": translate(left, 0), transition: 'none' });
          } else {
            $el.css({ transform: translate(left, 0), "-webkit-transform": translate(left, 0), transition: 'all '+speed+'ms ease' });
          }
        }

Other than this, Swipeshow's working great. Thanks for the resource!

EDIT: I just learned that jQuery 1.8+ does this for you (takes care of -moz, -webkit, and the like). Our site is using jQuery 1.7. This must explain why the issue has not come up before - and why you say your plugin requires jQuery 1.8+. Nevermind this issue!

Incompatible with mootools

Hi
I tried to use your plugin in multi-instances without any problem with jQuery only but the only presence of the mootools library (joomla 2.5 cms, loaded before jQuery) with implementation of all non conflict jQuery possible methods conducts to a non working page. It seems that the plugin is not correctly protected about libraries conflicts.
Have you made some test in this situation and what could be the solution?

Regards
Daniel

Swipeshow doesn't work on Nexus 4

It may be a device-specific issue, but on the multiple occasions that I've used Swipeshow, it did not work on Nexus 4. Works fine on iPhone + Galaxies

Testing for transitions returns true in IE7 and IE8

Having logged various variables to the console it appears that 'transitions' is returned as true in IE7 and IE8, when they do not support CSS transitions. I hacked this by forcing the plugin to use animate instead, but thought you'd like to know.

Automatic height

Hi, and compliments on a nice simple slider.

I am trying to make the slider responsive, with variable sized content.
Everything works well, but the height is really tricky.
Is it possible to somehow "make the slider the height of tallest image"?
It seems the slider needs a set height in the css, which is a bit tricky when the width (also css) is set to for example 100%.

Hope you understand the question :)

Stop slideshow after hover

Is there is any way to stop the slideshow compleatly (not pause) after hover or after user swipes one slide.

Youtube videos disappearing or gets cut on mouse hover

screen_shot_2013-10-03_at_12 16 08_pm

this was what I was talking about on the other issue regarding on the youtube/gdrive embedded videos. This is worse in Opera because it doesn't really show the iframes and it's not even clickable or some sort(clickable but nothing happens).

transition from :: last to first :: N to N +/- 2

Is there a way to make the transition from last to first... or from first to third/fourth/fifth happen without sliding through the bypassed items?

basically a simple transition to the element, not a slide past every element until you get to the one you want?

if a slideshow has 10 elements, and you jump from 1 to 10, or when it hits 10 and goes back to 1, it will slide through 10 frames quickly and its not attractive (not as bad or noticeable when there's 3), especially when they are large (500px wide or more) frames

Reverse interaction direction

Would be nice to have an option, possible to change at runtime, to just "reverse" the direction of the interaction.

This would be useful to applications that run in touch-screen computers where UI rotation changes at software level and the OS doesn't adapt.

width: 100%

When I enter % width for my .slideshow for some reason the slideshow disapears.

swipeshow().next() swipes 2 slides at once

I have a problem where calling "next()" nothing happens, but on calling next one more time the swipeshow swipes 2 slides at once. So it seems like the first event is not fired and then stacks up for the next call to next().

Im using the swipeshow inside an iFrame (Unfortunately needed becasue of the architecture)

Any idea as to why this is happening?

Flickering

From Rico Mossesgeld: "Display: none hides it, but there's some flickering. Seen on mobile safari and chrome." "Seems to occur during slide animation, again despite display: none"

http://8list.ph

Just a little documentation issue

for your HTML markup section (https://github.com/rstacruz/swipeshow#html-markup)

it looks like you broke from tradition. For most you're using a wrapping class of "slideshow", for the html-markup section you used "swipeshow", which is fine, if different from the rest of the examples, but in your description text above it your mind seems stuck between the two say, "or even .swideshow!" which is an amalgamation of the two.

(as a side note, in the css right below you're also using a selector of .swipeshow instead of the standard slideshow)

Looking forward to trying this out on my client's new site!

Height 100%

Is it possible to set height to 100% so picture have the correct size both in portrait and landscape ?

Make it Responsive

Currently you need to give the slideshow div container height and width in pixels..If given in % then the slides do not show.
If you fix this issue then it can be used responsively. :)

Compatibility

Hello,
Was just using this up on a project, I'm currently doing a cross-browser test of our website, and found that it doesn't work on Opera? It only displays the first slide and doesn't change content. Am i missing something here?

I'm currently looking at the documentation/readme but it doesn't state any browser that it wouldn't be compatible with. If I'm missing something here, I'm sorry that I filed the issue.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.