A plugin that detects the direction a user enters or leaves an element allowing you to reveal or hide content based on this direction.
$ npm install direction-reveal --save-dev
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.
;// Init with default setupconst directionRevealDemo = ;// Init with all options at default settingconst directionRevealDefault =;
||'.direction-reveal'||String||Container element selector.|
||'.direction-reveal__card'||String||Item element selector.|
||'enter'||String||Animation CSS class postfix for enter event.|
||'leave'||String||Animation CSS class postfix for leave event.|
||true||Boolean||Adds touch event to show content on first click then follow link on the second click.|
||250||Number(ms)||The touch length in ms to trigger the reveal, this is to prevent triggering if user is scrolling.|
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.
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.
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).
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.
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.
Clone or download from Github.
$ npm install$ gulp serve
MIT © Nigel O Toole