Minimal Swipeable Gallery In Pure JavaScript – SwiperBox

Category: Javascript , Slideshow | November 17, 2021
Author:vladimirnetworks
Views Total:2,136 views
Official Page:Go to website
Last Update:November 17, 2021
License:MIT

Preview:

Minimal Swipeable Gallery In Pure JavaScript –  SwiperBox

Description:

SwiperBox is a tiny JavaScript swiper library to create a touch-enabled, mobile-friendly gallery with support for swipe and drag events.

How to use it:

1. Download the package and insert the SwiperBox.js script into the HTML file.

<script src="SwiperBox.js"></script>

2. Define an array of items to be displayed in the gallery.

myItems = [
  '<div class="myitem"><img src="1.jpg" /></div>',
  '<div class="myitem"><img src="2.jpg" /></div>',
  '<div class="myitem"><img src="3.jpg" /></div>'
]

3. Initialize the swipeable gallery.

var mySwipe = new SwiperBox({
    items: myItems
});

4. Append the gallery to anywhere on the webpage.

mySwipe.HTMLElement.style.width = "400px";
mySwipe.HTMLElement.classList.add("mygal");
document.getElementById("example").appendChild(mySwipe.HTMLElement);

5. Handle the click event on the gallery items.

mySwipe.onClick = function(index,elem) {
  alert("clicked on index"+index);
}

6. Go to a specific item.

mySwipe.GoTo(2)

Changelog:

11/17/2021

  • Add GoTo method for swipe to elemets by index

You Might Be Interested In:


One thought on “Minimal Swipeable Gallery In Pure JavaScript – SwiperBox

  1. Ronny

    Hi,

    is it possible to create a loop between the pictures? so that picture one comes after the last one ?

    best Ronny

    Reply

Leave a Reply