slider-pro-js: Responsive Touch Slider With Thumbnail Navigation

Category: Slider , Slideshow | October 13, 2026
Authorbqworks
Last UpdateOctober 13, 2026
LicenseMIT
Views0 views
slider-pro-js: Responsive Touch Slider With Thumbnail Navigation

slider-pro-js is a vanilla JavaScript slider library for responsive image galleries and content carousels.

It supports swipe navigation, multi-slide layouts, and thumbnail strips with images, text, or HTML content.

Features

  • Horizontal, vertical, and right-to-left slide navigation.
  • Infinite looping, autoplay, and fade transitions.
  • Full-width, full-window, and fullscreen viewing modes.
  • Touch, mouse, and keyboard controls.
  • Configurable thumbnail placement and navigation arrows.
  • Animated or static text and HTML layers.
  • Responsive breakpoints and variable-size slides.
  • Lazy-loaded images and high-density image sources.
  • Automatic playback handling for video slides.
  • URL hashes for opening individual slides.

How To Use It

Installation

Load the compiled stylesheet and the core script from a CDN.

<link rel="stylesheet" href="https://unpkg.com/[email protected]/build/slider-pro.css">
<script src="https://unpkg.com/[email protected]/build/slider-pro.js"></script>

Basic Usage

Create the .slider-pro element with a .sp-slides container. Each .sp-slide is one slide, and .sp-image identifies a slide’s main image.

<div id="photo-slider" class="slider-pro">
  <div class="sp-slides">
    <div class="sp-slide">
      <img class="sp-image" src="images/coast.jpg" alt="Rocky coastline">
    </div>
    <div class="sp-slide">
      <img class="sp-image" src="images/mountains.jpg" alt="Mountain range">
    </div>
    <div class="sp-slide">
      <img class="sp-image" src="images/forest.jpg" alt="Forest trail">
    </div>
  </div>
</div>
<script>
const slider = new SliderPro('#photo-slider', {
  width: 900,
  height: 500,
  arrows: true,
  buttons: true,
  autoplay: false
});
</script>

npm Package and Bundlers

For a modern web project, use the following imports with the #photo-slider markup from Basic Usage.

npm install slider-pro-js

import SliderPro, { Autoplay, Buttons, TouchSwipe } from 'slider-pro-js';
import 'slider-pro-js/css';
const slider = new SliderPro('#photo-slider', {
  addOns: [Autoplay, Buttons, TouchSwipe],
  width: 900,
  height: 500
});

Browser ES Module

The jsDelivr ES module endpoint is another installation option. Use the stylesheet and #photo-slider markup from Basic Usage. Put this import inside a <script type="module"> element after the markup in place of the browser-build initialization.

import SliderPro, { Autoplay, Buttons, TouchSwipe } from
  'https://cdn.jsdelivr.net/npm/[email protected]/+esm';
new SliderPro('#photo-slider', {
  addOns: [Autoplay, Buttons, TouchSwipe]
});

Create a Gallery With Thumbnails

Place the .sp-thumbnails container after .sp-slides. The two images in this example have matching thumbnail images. You can also place a .sp-thumbnail inside each slide or use HTML content in a thumbnail.

<div id="gallery" class="slider-pro">
  <div class="sp-slides">
    <div class="sp-slide">
      <img class="sp-image" src="images/item-1.jpg" alt="First product view">
    </div>
    <div class="sp-slide">
      <img class="sp-image" src="images/item-2.jpg" alt="Second product view">
    </div>
  </div>
  <div class="sp-thumbnails">
    <img class="sp-thumbnail" src="images/item-1-thumb.jpg" alt="View one">
    <img class="sp-thumbnail" src="images/item-2-thumb.jpg" alt="View two">
  </div>
</div>
const gallery = new SliderPro('#gallery', {
  width: 800,
  height: 450,
  autoplay: false,
  thumbnailsPosition: 'bottom',
  thumbnailWidth: 110,
  thumbnailHeight: 70,
  thumbnailArrows: true
});

Change Settings at Responsive Breakpoints

Replace the gallery initialization above with this configuration to move the thumbnail strip below the slider on narrow screens. Each breakpoint starts from the original settings. Repeat values that must apply at multiple widths.

const gallery = new SliderPro('#gallery', {
  width: 960,
  height: 480,
  thumbnailsPosition: 'right',
  thumbnailWidth: 120,
  breakpoints: {
    800: {
      thumbnailsPosition: 'bottom',
      thumbnailWidth: 100
    },
    500: {
      thumbnailsPosition: 'bottom',
      thumbnailWidth: 65,
      thumbnailHeight: 50
    }
  }
});

Display Animated Text Layers

Insert elements with the .sp-layer class inside a slide. Use layer data attributes for positioning, animation direction, and delays. The .sp-black, .sp-padding, and .sp-rounded classes apply the included layer styles. If the slider width is percentage-based and you need proportional layer scaling, specify a numeric autoScaleReference.

<div class="sp-slide">
  <img class="sp-image" src="images/city.jpg" alt="City skyline at dusk">
  <h2 class="sp-layer sp-black sp-padding sp-rounded"
      data-position="bottomLeft"
      data-horizontal="24"
      data-vertical="24"
      data-show-transition="left"
      data-show-duration="500"
      data-hide-transition="right">
    Explore the city
  </h2>
</div>

Lazy-Load Images and Supply Responsive Sources

For the built-in lazy-loading module, place a placeholder in src and the real image in data-src. data-small, data-medium, and data-large select alternative images at the configured slider-width thresholds. Native srcset is also available for responsive image markup.

<div class="sp-slide">
  <img class="sp-image"
       src="images/placeholder.gif"
       data-src="images/landscape.jpg"
       data-small="images/landscape-small.jpg"
       data-medium="images/landscape-medium.jpg"
       data-large="images/landscape-large.jpg"
       alt="Landscape at sunrise">
</div>

Display Video Slides

Use .sp-video for an HTML5 video or a YouTube, Vimeo, or Video.js player. Slider Pro expects enablejsapi=1 on a YouTube iframe and api=1 on a Vimeo iframe for its player integration.

<div class="sp-slide">
  <video class="sp-video" controls preload="none"
         poster="images/video-poster.jpg" width="800" height="450">
    <source src="media/demo.mp4" type="video/mp4">
  </video>
</div>

Control Slides and Listen for Changes

Use the slider instance from Basic Usage for additional controls. Place this button after the slider element. Slide indexes start at 0, and event.detail includes the selected and previous indexes for gotoSlide.

<button id="next-photo" type="button">Next photo</button>
slider.addEventListener('gotoSlide', (event) => {
  console.log('Selected slide:', event.detail.index);
});
document.querySelector('#next-photo').addEventListener('click', () => {
slider.nextSlide();
});

Configuration Options

Pass an options object as the second argument to new SliderPro(selector, options).

Core Sizing and Layout

OptionDefaultDescription
width500Slide width in pixels or a CSS length such as '100%' or '100vw'.
height300Slide height in pixels or a CSS length.
responsivetrueScales slides to the available space. Fixed dimensions can act as maximum dimensions.
aspectRatio-1Overrides slide height to maintain a given width-to-height ratio. -1 disables this behavior.
imageScaleMode'cover'Main image scaling: 'cover', 'contain', 'exact', or 'none'.
centerImagetrueCenters the main image.
allowScaleUptruePermits images to grow beyond their native dimensions.
autoHeightfalseMatches slider height to the selected slide.
autoSlideSizefalseAllows variable widths for horizontal slides or variable heights for vertical slides.
startSlide0Zero-based index of the initially selected slide.
shufflefalseRandomizes slide order during initialization.
orientation'horizontal''horizontal' or 'vertical' slide arrangement.
forceSize'none''none', 'fullWidth', or 'fullWindow'.
looptrueEnables wraparound slide navigation.
slideDistance10Distance between slides in pixels.
slideAnimationDuration700Slide transition duration in milliseconds.
heightAnimationDuration700Height transition duration in milliseconds.
visibleSize'auto'Extends the visible slider area to expose neighboring slides.
centerSelectedSlidetrueCenters the selected slide when multiple slides are visible.
rightToLeftfalseUses right-to-left slide direction.

Modules, Motion, and Navigation

OptionDefaultDescription
addOns[]Add-on classes to initialize with module imports.
fadefalseUses a fade transition between slides.
fadeOutPreviousSlidetrueFades out the previous slide during the fade transition.
fadeDuration500Fade duration in milliseconds.
autoplaytrueEnables automatic slide changes.
autoplayDelay5000Interval between autoplay transitions in milliseconds.
autoplayDirection'normal''normal' or 'backwards'.
autoplayOnHover'pause''pause', 'stop', or 'none' on hover.
arrowsfalseDisplays previous and next arrows.
fadeArrowstrueReveals slide arrows on hover.
buttonstrueDisplays pagination buttons.
keyboardtrueEnables keyboard slide navigation.
keyboardOnlyOnFocusfalseRestricts keyboard control to a focused slider.
touchSwipetrueEnables touch and mouse dragging of slides.
touchSwipeThreshold50Minimum swipe distance in pixels.
fadeCaptiontrueFades captions during slide changes.
captionFadeDuration500Caption fade duration in milliseconds.
fullscreenfalseDisplays the fullscreen control.
fadeFullscreentrueReveals the fullscreen control on hover.

Layers, Images, Thumbnails, and Video

OptionDefaultDescription
waitForLayersfalseWaits for animated layers to hide before certain slide changes.
autoScaleLayerstrueScales layers as slides shrink.
autoScaleReference-1Reference width for layer scaling. -1 uses the configured slide width when possible.
smallSize480Slider-width threshold for small images.
mediumSize768Slider-width threshold for medium images.
largeSize1024Slider-width threshold for large images.
updateHashfalseUpdates the location hash to identify the selected slide.
reachVideoAction'none''playVideo' or 'none' when selecting a video slide.
leaveVideoAction'pauseVideo''stopVideo', 'pauseVideo', 'removeVideo', or 'none' when leaving a video slide.
playVideoAction'stopAutoplay''stopAutoplay' or 'none' when video playback starts.
pauseVideoAction'none''startAutoplay' or 'none' when video playback pauses.
endVideoAction'none''startAutoplay', 'nextSlide', 'replayVideo', or 'none' when playback ends.
thumbnailWidth100Thumbnail width in pixels.
thumbnailHeight80Thumbnail height in pixels.
thumbnailsPosition'bottom''top', 'bottom', 'right', or 'left'.
thumbnailPointerfalseDisplays a selection pointer on the current thumbnail.
thumbnailArrowsfalseShows thumbnail-strip arrows.
fadeThumbnailArrowstrueControls hover-based fading of thumbnail arrows.
thumbnailTouchSwipetrueEnables swiping the thumbnail strip.
breakpointsnullMaps browser-width thresholds to sets of slider options.

Public Methods

MethodDescription
gotoSlide(index)Selects the slide at the zero-based index.
nextSlide()Selects the next slide.
previousSlide()Selects the previous slide.
getSlideAt(index)Returns the data object for a slide.
getSelectedSlide()Returns the current slide index.
getTotalSlides()Returns the slide count.
update()Refreshes the slider after markup changes.
resize()Recalculates slider dimensions.
addEventListener(type, handler)Registers a slider event handler.
removeEventListener(type)Removes the handler registered for that event identifier.
destroy()Removes slider behavior and restores its original markup state.

Events

Register slider events with addEventListener() on the instance.

EventWhen it fires
beforeInitBefore slider initialization.
initAfter initialization.
beforeUpdateBefore a slider update.
updateDuring the slider’s update sequence.
beforeResizeBefore recalculation of slider size.
resizeAfter the slider is resized.
gotoSlideWhen a slide is selected. detail.index and detail.previousIndex identify the current and prior slides.
gotoSlideCompleteAfter the slide transition completes. detail.index identifies the selected slide.

HTML Classes and Data Attributes

Slide and Thumbnail Markup

ClassPurpose
.slider-proRoot slider container.
.sp-slidesWrapper for the slide elements.
.sp-slideIndividual slide.
.sp-imageMain slide image.
.sp-captionCaption beneath a slide.
.sp-thumbnailsWrapper for an independent thumbnail strip.
.sp-thumbnailThumbnail content, either in the strip or inside a slide.
.sp-thumbnail-imageImage inside a composite thumbnail.
.sp-thumbnail-textText inside a composite thumbnail.
.sp-layerPositioned or animated HTML layer inside a slide.
.sp-videoVideo content managed by the Video module.

Layer Styling Classes

ClassPurpose
.sp-staticKeeps the layer visible rather than animating its entrance and exit.
.sp-blackDark translucent layer background with white text.
.sp-whiteLight translucent layer background with dark text.
.sp-paddingApplies 10 pixels of padding.
.sp-roundedRounds the layer corners.

Layer Data Attributes

Use these attributes on elements with .sp-layer. data-position accepts topLeft, topCenter, topRight, bottomLeft, bottomCenter, bottomRight, centerLeft, centerRight, and centerCenter. The default is topLeft. Transition directions accept left, right, up, and down.

AttributePurpose
data-widthLayer width in pixels or a percentage.
data-heightLayer height in pixels or a percentage.
data-depthLayer stacking order.
data-positionReference position within the slide.
data-horizontalHorizontal offset from the reference position.
data-verticalVertical offset from the reference position.
data-show-transitionDirection used when the layer appears.
data-show-offsetStarting distance for the entrance animation.
data-show-durationEntrance animation duration.
data-show-delayDelay before the entrance animation.
data-hide-transitionDirection used when the layer disappears.
data-hide-offsetEnding distance for the exit animation.
data-hide-durationExit animation duration.
data-hide-delayDelay before the exit animation.
data-stay-durationTime before the layer hides automatically.

Image Source Attributes

AttributePurpose
data-srcSource image used by the lazy-loading module.
data-retinaHigh-density display image.
data-smallAlternative image for small slider widths.
data-mediumAlternative image for medium slider widths.
data-largeAlternative image for large slider widths.
data-retinasmallHigh-density version of the small image.
data-retinamediumHigh-density version of the medium image.
data-retinalargeHigh-density version of the large image.

CSS Module Imports

The npm package exports its complete stylesheet through slider-pro-js/css. The following public imports are available when a bundler can process CSS imports. Only import the module styles your project uses, along with the core stylesheet.

ImportStyles
slider-pro-js/cssAll bundled styles.
slider-pro-js/css/coreSlider structure and base slides.
slider-pro-js/css/arrowsPrevious and next controls.
slider-pro-js/css/buttonsPagination controls.
slider-pro-js/css/captionSlide captions.
slider-pro-js/css/fullscreenFullscreen control.
slider-pro-js/css/layersLayer styles and presets.
slider-pro-js/css/thumbnailsThumbnail containers and items.
slider-pro-js/css/thumbnail-arrowsThumbnail-strip arrows.
slider-pro-js/css/thumbnail-touch-swipeThumbnail swipe styling.
slider-pro-js/css/touch-swipeMain slider drag styling.
slider-pro-js/css/videoVideo slide styling.

Available Modules

The npm entry point exports the following add-on classes. The compiled browser build includes all of them. Pass the desired class constructors in addOns when importing the JavaScript as modules.

Add-onPurpose
ArrowsPrevious and next controls.
AutoplayAutomatic slide progression.
BreakpointsWidth-dependent settings.
ButtonsPagination buttons.
CaptionSlide captions.
ConditionalImagesAlternative images at size thresholds.
DeepLinkingURL-hash navigation.
FadeFade transitions.
FullscreenFullscreen button and mode.
KeyboardKeyboard navigation.
LayersPositioned or animated slide content.
LazyLoadingDeferred image loading.
RetinaHigh-density image selection.
ThumbnailsThumbnail navigation.
ThumbnailArrowsThumbnail-strip arrows.
ThumbnailTouchSwipeSwipe navigation in the thumbnail strip.
TouchSwipeSwipe and drag navigation in the main slider.
VideoPlayback handling for video slides.

Alternatives & Related Resources

You Might Be Interested In:


Leave a Reply