Categories: CSSScriptWeb Design

Fast, Extensible, Touch-enabled Carousel & Slider JS Library – Smooothy

Smooothy is a lightweight, framework-agnostic JavaScript slider library for creating smooth, performant, interactive, touch-enabled carousels.

It can help you handle the tricky parts of slider mechanics, like smooth scrolling, infinite looping, snapping, and touch interactions, while staying out of your way on styling and advanced features.

Features:

  • High Performance: It’s built on requestAnimationFrame loop for updates.
  • Extensibility: You can easily add your own methods and UI.
  • Infinite Scrolling: Seamless infinite looping.
  • Snapping: Optional snapping to slide positions.
  • Touch & Mouse Interactions: Handles drag, swipes (with horizontal/vertical detection), and momentum.
  • Parallax Ready: Provides parallaxValues in its update callback for creating depth effects.
  • Responsive: Automatically recalculates dimensions on resize.
  • Customizable Animation: Fine-tune animation with options like lerpFactor, speedDecay, and snapStrength.
  • WebGL Friendly: Better synchronization with WebGL rendering.
  • Event Callbacks: onSlideChange, onResize, onUpdate for hooking into the slider’s lifecycle.

See It In Action:


How To Use It:

1. Install Smooothy and import it into your project.

# NPM
$ npm install smooothy
// Core class only
import Core from "smooothy";
// Core with utilities like damp (useful for custom animations)
import Core, { damp } from "smooothy";

2. Create a slider wrapper and direct children as slides.

<div class="slider-wrapper" data-slider>
  <div class="slide">Slide 1</div>
  <div class="slide">Slide 2</div>
  <div class="slide">Slide 3</div>
  ... more slides here ...
</div>

3. The basic styling for the slider. If you want the content of the slide to not touch the edges due to this padding, you’d put another div inside your slide element and style that as the visual slide.

[data-slider] {
  display: flex;
  overflow: hidden;
}

[data-slider] > * {
  flex-shrink: 0;
  width: 100%; /* Or your specific slide width, e.g., 300px */  /* For gaps:
  padding-right: 0.5rem;
  padding-left: 0.5rem;
  box-sizing: border-box;
  */}

4. Initialize the slider and run its update method in an animation loop.

// Select your wrapper element
const sliderWrapper = document.querySelector("[data-slider]");

// Create a new slider instance
const slider = new Core(sliderWrapper, {
  // options here
});

// Update the slider (typically in an animation loop)
function animate() {
  slider.update();
  requestAnimationFrame(animate);
}
animate();

// Don't forget to clean up when the slider is no longer needed
// slider.destroy();

5. Available options to customize the behavior of your slider.

  • infinite (boolean, default: true): Enables infinite looping.
  • snap (boolean, default: true): Enables snapping to slide positions.
  • dragSensitivity (number, default: 0.005): Multiplier for drag sensitivity.
  • lerpFactor (number, default: 0.3): Controls animation smoothness (lower is smoother). I’ve found tweaking this is key for matching the feel of other site animations.
  • scrollSensitivity (number, default: 1): Multiplier for scroll wheel sensitivity.
  • snapStrength (number, default: 0.1): How strongly the slider snaps.
  • speedDecay (number, default: 0.85): How quickly sliding speed decays.
  • bounceLimit (number, default: 1): Max overscroll when infinite is false.
  • scrollInput (boolean, default: false): Enables mouse wheel/trackpad scrolling. Requires virtualScroll under the hood.
  • setOffset (function): Custom function ({itemWidth, wrapperWidth}) => itemWidth to define slide end offset. Useful for non-standard alignments.
  • virtualScroll (object): Config for virtual-scroll behavior (e.g., mouseMultiplier, touchMultiplier).
  • onSlideChange (function): Callback (currentSlide, previousSlide) => {} when active slide changes.
  • onResize (function): Callback (instance) => {} when slider is resized.
  • onUpdate (function): Callback (instance) => {} on each update frame. This is where you can hook in custom animations using instance.speed, instance.deltaTime, etc.
const slider = new Core(sliderWrapper, {
  infinite: true,
  snap: true,
  dragSensitivity: 0.005,
  lerpFactor: 0.3,
  scrollSensitivity: 1,
  snapStrength: 0.1,
  speedDecay: 0.85,
  bounceLimit: 1,
  virtualScroll: {
    mouseMultiplier: 0.5,
    touchMultiplier: 2,
    firefoxMultiplier: 30,
    useKeyboard: false,
    passive: true,
  },
  setOffset: ({ itemWidth, wrapperWidth }) => itemWidth,
  scrollInput: false,
  onSlideChange: (currentSlide, previousSlide) => {},
  onResize: (instance) => {},
  onUpdate: (instance) => {},
});

6. Control over the slider programmatically with the following API methods.

  • Navigation: slider.goToNext(), slider.goToPrev(), slider.goToIndex(n)
  • State Control: slider.init(), slider.kill() (disables), slider.destroy() (full cleanup), slider.paused = true/false, slider.snap = true/false
  • State Queries/Setters:
    • slider.currentSlide: Get current slide index.
    • slider.progress: Get slider progress (0-1).
    • slider.target: Get/Set target position (setting it lerps).
    • slider.current: Get/Set current position (setting it moves instantly). For an instant jump, set both: slider.current = slider.target = 5.
    • slider.deltaTime: Time since last update (seconds). Crucial for frame-rate independent animations in onUpdate.
    • slider.viewport: Object with itemWidth, wrapperWidth, totalWidth.
    • slider.isVisible: Boolean if the slider is in view.

The post Fast, Extensible, Touch-enabled Carousel & Slider JS Library – Smooothy appeared first on CSS Script.

rssfeeds-admin

Share
Published by
rssfeeds-admin

Recent Posts

City sales tax revenue shows unexpected surge in March

April 22, 2026 It’s somewhat unclear why, but sales tax revenue in Sioux Falls took…

5 minutes ago

Downtown boutique enhances refillable section after receiving small-business grant

April 22, 2026 A downtown Sioux Falls boutique is expanding a key part of its…

5 minutes ago

News alert: BreachLock’s integrated attack validation platform debuts in Gartner AEV category

NEW YORK, Apr. 21, 2026, CyberNewswire—BreachLock, a global leader in offensive security, today announced it…

10 minutes ago

Hospitality platform KabinHotel.xyz integrates sustainability into hotel operations

KabinHotel.xyz – GoDaddy customer – (Japan) The .xyz community includes organizations building tools, platforms, and…

10 minutes ago

Hear Classical Music Composed by Friedrich Nietzsche

A philosopher perhaps more widely known for his prodigious mustache than for the varieties of…

21 minutes ago

Report: AEP CEO Tops Utility Pay With $36 Million Compensation

WASHINGTON, D.C. (WOWO) A new report examining executive compensation across the utility sector shows continued…

44 minutes ago

This website uses cookies.