Universal Swipe.js (swipe-js-iso)

2.1.5 · maintenance · verified Wed Apr 22

swipe-js-iso is a lightweight, dependency-free JavaScript library for creating touch-enabled carousels and sliders, specifically forked from the original Swipe.js project. It aims to be compatible with 'universal' (isomorphic) applications, meaning it can theoretically be used in both browser and server-side rendering contexts (though typically client-side focused for DOM manipulation). The current stable version is 2.1.5, with the last publish being 7 years ago, suggesting a maintenance or inactive release cadence rather than active development. Its key differentiators include its minimal footprint and lack of external dependencies, providing a simple, performant solution for basic image or content swiping, particularly when alternatives like Swiper.js might be considered too heavy or feature-rich.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to set up a basic swipeable carousel using `swipe-js-iso` with HTML, CSS, and JavaScript. It initializes the slider, configures common options like auto-play and transition speed, and exposes API methods (`prev`, `next`) for external controls.

<!-- index.html -->
<style>
  .swipe {
    overflow: hidden;
    visibility: hidden;
    position: relative;
  }
  .swipe-wrap {
    overflow: hidden;
    position: relative;
  }
  .swipe-wrap > div {
    float: left;
    width: 100%;
    position: relative;
  }
</style>

<div id="slider" class="swipe">
  <div class="swipe-wrap">
    <div><h2>Slide 1</h2><p>Content for slide 1</p></div>
    <div><h2>Slide 2</h2><p>Content for slide 2</p></div>
    <div><h2>Slide 3</h2><p>Content for slide 3</p></div>
  </div>
</div>

<button onclick="mySwipe.prev()">Prev</button>
<button onclick="mySwipe.next()">Next</button>

<script type="module">
  import Swipe from 'swipe-js-iso';

  document.addEventListener('DOMContentLoaded', () => {
    const mySwipe = new Swipe(document.getElementById('slider'), {
      startSlide: 0,
      speed: 400,
      auto: 3000,
      continuous: true,
      disableScroll: false,
      stopPropagation: false,
      callback: function(index, elem) {
        console.log('Slide changed to:', index, elem);
      },
      transitionEnd: function(index, elem) {
        console.log('Transition ended for:', index, elem);
      }
    });

    // Expose for global buttons
    window.mySwipe = mySwipe;

    console.log('Total slides:', mySwipe.getNumSlides());
    console.log('Current slide position:', mySwipe.getPos());
  });
</script>

view raw JSON →