npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@wmh/scrollbox

v2.0.1

Published

Modern vanilla JavaScript scrollbox plugin for carousels and marquees. Zero dependencies. jQuery wrapper included for backward compatibility.

Downloads

218

Readme

ScrollBox

npm version Zero Dependencies Vanilla JS TypeScript License Sponsor

Version 2.0 - Modern vanilla JavaScript scrolling plugin 🎉

📦 Note: This package is available on npm as @wmh/scrollbox. It's a modern, dependency-free vanilla JavaScript library with optional jQuery support for backward compatibility.

ScrollBox is a lightweight, zero-dependency plugin that enables you to scroll a list of HTML elements (text, images, etc.) like a carousel slider or traditional marquee. Built with modern ES6+ JavaScript with optional jQuery support for backward compatibility.

Features

  • Zero dependencies - Pure vanilla JavaScript
  • 🚀 Modern ES6+ with backward compatibility
  • 📦 Simple and lightweight (~5KB minified)
  • ↕️ Vertical and horizontal scroll
  • ▶️ Auto play with customizable timing
  • 🔄 Multiple instances on one page
  • ⏸️ Pause on hover
  • 🎛️ Extensive configuration options
  • ⬅️➡️ Prev / Next navigation buttons
  • 🎯 Queue container for advanced usages
  • 🔌 Optional jQuery plugin wrapper for legacy support
  • 🐛 Bug fixes for Chrome scroll jumping (Issue #38)
  • 📱 Better handling of browser zoom/resize (Issue #37)

Installation

NPM

npm install @wmh/scrollbox

Note: This is a modern vanilla JavaScript library with zero dependencies! Optional jQuery wrapper included for backward compatibility.

CDN

<script src="https://cdn.jsdelivr.net/npm/@wmh/scrollbox@2/dist/scrollbox.min.js"></script>

Direct Download

Download scrollbox.js or jquery.scrollbox.js from this repository.

GitHub

git clone https://github.com/wmh/scrollbox.git

Basic Usage

Modern Vanilla JavaScript (Recommended)

1. Include ScrollBox

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

2. Create HTML structure

<div id="demo" class="scroll-text">
  <ul>
    <li>item 1</li>
    <li>item 2</li>
    <li>item 3</li>
  </ul>
</div>

3. Style your elements

.scroll-text {
  width: 300px;
  height: 100px;
  overflow: hidden;
}

4. Initialize

const element = document.getElementById('demo');
const scrollbox = new ScrollBox(element, {
  direction: 'vertical',
  autoPlay: true
});

jQuery (Legacy Support)

1. Include jQuery and ScrollBox

<script src="https://code.jquery.com/jquery-3.7.1.min.js"></script>
<script src="jquery.scrollbox.js"></script>

2. Initialize with jQuery

$('#demo').scrollbox({
  direction: 'vertical',
  autoPlay: true
});

API Methods

Vanilla JavaScript

const scrollbox = new ScrollBox(element, options);

// Trigger events
element.dispatchEvent(new Event('forward'));
element.dispatchEvent(new Event('backward'));
element.dispatchEvent(new CustomEvent('resetClock', { detail: { delay: 5 } }));
element.dispatchEvent(new CustomEvent('speedUp', { detail: { speed: 16 } }));
element.dispatchEvent(new CustomEvent('speedDown', { detail: { speed: 64 } }));
element.dispatchEvent(new CustomEvent('updateConfig', { 
  detail: { autoPlay: false, speed: 50 } 
}));

// Destroy instance
scrollbox.destroy();

jQuery API

$('#demo').trigger('forward');
$('#demo').trigger('backward');
$('#demo').trigger('resetClock', [5]);
$('#demo').trigger('speedUp', [16]);
$('#demo').trigger('speedDown', [64]);
$('#demo').trigger('updateConfig', [{ autoPlay: false }]);

Migration Guide (v1 to v2)

If you're using jQuery (minimal changes needed)

Your existing code should work with minimal changes. Just update to the latest version.

Migrating to Vanilla JavaScript (recommended)

// Old jQuery way
$('#demo').scrollbox({ direction: 'vertical' });
$('#demo').trigger('forward');

// New vanilla JS way
const scrollbox = new ScrollBox(document.getElementById('demo'), {
  direction: 'vertical'
});
document.getElementById('demo').dispatchEvent(new Event('forward'));

Browser Support

  • Chrome/Edge (latest)
  • Firefox (latest)
  • Safari (latest)
  • Opera (latest)
  • IE 11+ (with transpiled ES5 version)

Demos

http://wmh.github.io/scrollbox/

Configuration Options

| Option | Type | Default | Description | |--------|------|---------|-------------| | linear | Boolean | false | Use linear scrolling animation | | startDelay | Number | 2 | Initial delay before scrolling starts (seconds) | | delay | Number | 3 | Delay between scroll events (seconds) | | step | Number | 5 | Distance of each step in pixels (for linear mode) | | speed | Number | 32 | Animation speed in milliseconds | | switchItems | Number | 1 | Number of items to switch per scroll | | direction | String | 'vertical' | Scroll direction: 'vertical' or 'horizontal' | | distance | String/Number | 'auto' | Scroll distance or 'auto' | | autoPlay | Boolean | true | Enable auto-scrolling | | onMouseOverPause | Boolean | true | Pause on mouse hover | | infiniteLoop | Boolean | true | Enable infinite looping | | switchAmount | Number | 0 | Total switches before stopping (0 = infinite) | | afterForward | Function | null | Callback after forward scroll | | afterBackward | Function | null | Callback after backward scroll | | triggerStackable | Boolean | false | Allow stacking trigger events |

Advanced Examples

Non-infinite Loop (Vanilla JS)

const scrollbox = new ScrollBox(document.getElementById('demo'), {
  infiniteLoop: false,
  switchAmount: 3
});

With Callback Functions (Vanilla JS)

const scrollbox = new ScrollBox(document.getElementById('demo'), {
  afterForward: function(data) {
    console.log('Scrolled forward', data.switchCount);
    if (data.switchCount >= 3) {
      // Trigger backward
      const event = new Event('backward');
      this.dispatchEvent(event);
    }
  },
  afterBackward: function(data) {
    console.log('Scrolled backward', data);
  }
});

Manual Controls (Vanilla JS)

const scrollbox = new ScrollBox(document.getElementById('demo'), {
  autoPlay: false
});

// Control with buttons
document.getElementById('forward-btn').addEventListener('click', () => {
  const event = new Event('forward');
  document.getElementById('demo').dispatchEvent(event);
});

document.getElementById('backward-btn').addEventListener('click', () => {
  const event = new Event('backward');
  document.getElementById('demo').dispatchEvent(event);
});

jQuery Examples (Legacy)

// Non-infinite loop
$('#demo').scrollbox({
  infiniteLoop: false,
  switchAmount: 3
});

// With callbacks
$('#demo').scrollbox({
  afterForward: function (data) {
    console.log(data.currentFirstChild);
    if (data.switchCount >= 3) {
      $(this).trigger('backward');
    }
  },
  afterBackward: function (data) {
    console.log(data);
  }
});

// Manual controls
$('#forward-btn').click(function() {
  $('#demo').trigger('forward');
});
$('#backward-btn').click(function() {
  $('#demo').trigger('backward');
});

Support the Project

If you find ScrollBox helpful, consider sponsoring me on GitHub ☕ Your support helps maintain and improve this project!

License

jQuery Scrollbox is open-sourced software licensed under the MIT license