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

direction-reveal

v2.0.2

Published

A plugin that detects the direction a user enters or leaves an element allowing you to reveal or hide content based on this direction.

Downloads

63

Readme

Direction Reveal

A plugin that detects the direction a user enters or leaves an element allowing you to reveal or hide content based on this direction.

View demo

Installation

$ npm install direction-reveal --save-dev

Usage

Import JS

The script is an ES6(ES2015) module but the compiled version is included in the build as "src/scripts/direction-reveal-umd.js". You can also copy "src/scripts/direction-reveal.js" into your own site if your build process can accommodate ES6 modules.

import DirectionReveal from 'direction-reveal';

// Init with default setup
const directionRevealDemo = DirectionReveal();

// Init with all options at default setting
const directionRevealDefault = DirectionReveal({
  selector: '.direction-reveal',
  itemSelector: '.direction-reveal__card',
  animationName: 'swing',
  animationPostfixEnter: 'enter',
  animationPostfixLeave: 'leave',
  enableTouch: true,
  touchThreshold: 250
});

Options

| Property | Default | Type | Description | | ----------------------- | --------------------------- | ---------- | ------------------------------------------------------------------------------------------------- | | selector | '.direction-reveal' | String | Container element selector. | | itemSelector | '.direction-reveal__card' | String | Item element selector. | | animationName | 'swing' | String | Animation class. | | animationPostfixEnter | 'enter' | String | Animation CSS class postfix for enter event. | | animationPostfixLeave | 'leave' | String | Animation CSS class postfix for leave event. | | enableTouch | true | Boolean | Adds touch event to show content on first click then follow link on the second click. | | touchThreshold | 250 | Number(ms) | The touch length in ms to trigger the reveal, this is to prevent triggering if user is scrolling. |

Import SASS

@import "node_modules/direction-reveal/src/styles/direction-reveal.scss";

Markup

<div class="direction-reveal">

  <a href="#" class="direction-reveal__card">
    <img src="images/image.jpg" alt="Image" class="img-fluid">

    <div class="direction-reveal__overlay direction-reveal__anim--enter">
      <h3 class="direction-reveal__title">Title</h3>
      <p class="direction-reveal__text">Description text.</p>
    </div>
  </a>

  ...
</div>

Using other tags

The demos use <a> tags for the "direction-reveal__card" but a <div> can be used as below, specifying the tabindex ensures keyboard navigation works as expected. They can all have a value of 0 and will follow the source order of the divs.

<div class="direction-reveal__card" tabindex="0">
  ...
</div>

Inverted animations

Most of the animations above can be inverted so the overlay is visible by default and animates out on hover. Change the class 'direction-reveal__anim--enter' to 'direction-reveal__anim--leave' for this effect.

You can also add the class 'direction-reveal__anim--enter' or 'direction-reveal__anim--leave' to the image to animate it at the same time as overlay. This effect can be seen in the Slide & Push demo.

Events

A 'directionChange' event is broadcast once a user enters/leaves an item with information about the action(enter,leave) and direction(top, right, bottom, left).

document.querySelector('#test').addEventListener('directionChange', (event) => { 
  console.log(`Action: ${event.detail.action} Direction: ${event.detail.direction}`);
});

Compatibility

Touch support

The plugin will detect touch support and reveal the hidden content on first click then follow link on the second click. This can be disabled with the option enableTouch.

Browser support

Supports all modern browsers(Firefox, Chrome and Edge) released as of January 2018. For older browsers you may need to include polyfills for Nodelist.forEach, Element.classList and Passive Event Listeners.

Demo site

Clone or download from Github.

$ npm install
$ gulp serve

Credits

Inspired by a Codepen by Noel Delgado, this Stack overflow answer, the article Get an Element's position using javascript and Images from Unsplash..

License

MIT © Nigel O Toole