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 🙏

© 2024 – Pkg Stats / Ryan Hefner

wallop

v2.4.1

Published

wallop is a minimal 4kb library for showing & hiding things

Downloads

642

Readme

wallop

Build Status npm version

Much more than just a slider

wallop is a minimal 4kb library for showing & hiding things.

❗️Important note Version 1 of WallopSlider is not compatible with version 2+. If you are still using v1, please note that I am no longer supporting it. Documentation, etc. has been moved to this branch.

About

In a nutshell, wallop takes a collection of HTML elements and Previous & Next buttons, and adds helper HTML classes in the correct elements based on whether you want to navigate forwards or backwards.

It basically just add the right classes in the right places at the right time.

With those classes, you can do an infinite number of things, controlling what's shown or hidden with CSS.

Examples

I've created a collection on Codepen with a few more examples, go take a 👀!

Benefits

  • Mobile first
  • Progressive enhancement
  • Transitions/Animations are all in CSS
  • Minimal JavaScript
  • Flexible & Scalable
  • Custom events and API available
  • 4KB minified
  • Dependency free

Install

With npm

$ npm install wallop

With bower

$ bower install wallop

Download You can download the latest version or checkout all the releases here.

Usage

Once you have downloaded Wallop, the first thing you need to do is include the CSS and the JavaScript.

CSS

<head>
  <link rel="stylesheet" href="path/to/wallop.css">
</head>

JavaScript

<script src="path/to/Wallop.min.js"></script>
<script>
  var wallopEl = document.querySelector('.Wallop');
  var slider = new Wallop(wallopEl);
</script>

commonJS

  var Wallop = require('Wallop');

ES6

  import Wallop from 'Wallop';

HTML

<div class="Wallop">
  <div class="Wallop-list">
    <div class="Wallop-item">…</div>
    <div class="Wallop-item">…</div>
    <div class="Wallop-item">…</div>
    <div class="Wallop-item">…</div>
    <div class="Wallop-item">…</div>
  </div>
  <button class="Wallop-buttonPrevious">Previous</button>
  <button class="Wallop-buttonNext">Next</button>
</div>

#protip You can set the starting slide with a .Wallop-item--current class.

Adding animations

Wallop has no animations by default, so if you want to animate the slides, you need to extend the default .Wallop class with an animation modifier and include the respective CSS into your HTML.

I have created a few basic animations which are ready for you to use out-of-the-box, you will find them in the /css directory.

Including animation CSS

<head>
  <link rel="stylesheet" href="path/to/wallop.css">
  <link rel="stylesheet" href="path/to/wallop-animation.css">
</head>

Extending with modifier

<div class="Wallop Wallop--fade">
...
</div>

Available animations

Here's a list of the available animation modifiers ready for you to use

  • Wallop--slide
  • Wallop--fade
  • Wallop--scale
  • Wallop--rotate
  • Wallop--fold
  • Wallop--vertical-slide

protip These animation helpers are especially helpful using if you are using wallop as a slider, but don't feel forced to use them, instead, feel free to take advantage of the classes wallop provides you with, and create you own! Like these guys did.

Options

Here's a list of options you can pass to Wallop

  • buttonPreviousClass: 'Wallop-buttonPrevious'
  • buttonNextClass: 'Wallop-buttonNext'
  • itemClass: 'Wallop-item'
  • currentItemClass: 'Wallop-item--current'
  • showPreviousClass: 'Wallop-item--showPrevious'
  • showNextClass: 'Wallop-item--showNext'
  • hidePreviousClass: 'Wallop-item--hidePrevious'
  • hideNextClass: 'Wallop-item--hideNext'
  • carousel: true

API

Wallop offers a basic API for you to use, so you can control it from your own buttons or gestures.

goTo(index)

This allows you to go to a specific slide index.

var slider = document.querySelector('.Wallop');
var Wallop = new Wallop(slider);

// Go to 2nd slide
Wallop.goTo(1);

#protip index starts at 0 👌

next()

This allows you to go to the next slide

var slider = document.querySelector('.Wallop');
var Wallop = new Wallop(slider);

// Go to next slide
Wallop.next();

previous()

This allows you to go to the previous slide

var slider = document.querySelector('.Wallop');
var Wallop = new Wallop(slider);

// Go to previous slide
Wallop.previous();

reset()

This resets all internal variables of Wallop. Useful when dynamically changing the number of items in your slider.

var slider = document.querySelector('.Wallop');
var Wallop = new Wallop(slider);

// Some function that will dynamically
// insert new itmes in Wallop
insertNewItems();

// Reset config
Wallop.reset();

Events

Wallop dispatches a Custom Event every time a slide changes, and it returns a detail object which contains the current slide index and the element you initiated Wallop with.

Listening to a slide change

var slider = document.querySelector('.Wallop');
var Wallop = new Wallop(slider);
var handler = function(event) {
  // event.detail.wallopEl
  // => <div class="Wallop">…</div>

  // event.detail.currentItemIndex
  // => number
};

// Listen to the handler
Wallop.on('change', handler);

// Remove the handler listener
Wallop.off('change', handler);

Real life examples

  • Google – uses wallop as a slideshow, transitioning the background colour and animating the hero image of each item
  • Warp – uses the power of wallop's API and Custom Events to control the items via the URL and to build a custom pagination
  • London Housing Headlines – uses wallop to display a collection of really cool headlines about London's housing crisis 👍
  • Strava Insights – uses wallop a a slideshow, transitioning and transforming the background images with delay

If you are using wallop, please do let me know by creating an issue and I'll make sure to add it to this list 👊

Limitations

Due to its simplicity, wallop has a few limitations. For example, it is not possible to have the slide position animation based on gesture, or it's not possible to include physics based animations based on gesture momentum.

If you want a slider which provides all these options, I highly recommend David Desandro's Flickity.

Contributing

Plese see CONTRIBUTING.md for more information.

Licensing

MIT © 2015 Pedro Duarte