├── .babelrc ├── .editorconfig ├── .gitignore ├── LICENSE ├── README.md ├── docs ├── images │ ├── mountain-1.jpg │ ├── mountain-2.jpg │ ├── mountain-3.jpg │ ├── mountain-4.jpg │ ├── mountain-5.jpg │ └── mountain-6.jpg ├── index.html ├── scripts │ ├── direction-reveal-umd.js │ ├── direction-reveal.js │ └── main.js └── styles │ ├── direction-reveal.css │ └── site.css ├── gulpfile.js ├── package-lock.json ├── package.json └── src ├── images ├── mountain-1.jpg ├── mountain-2.jpg ├── mountain-3.jpg ├── mountain-4.jpg ├── mountain-5.jpg └── mountain-6.jpg ├── index.html ├── scripts ├── direction-reveal-umd.js ├── direction-reveal.js └── main.js └── styles ├── direction-reveal.css ├── direction-reveal.scss ├── direction-reveal ├── _direction-reveal-animations.scss ├── _direction-reveal-variables.scss └── _direction-reveal.scss ├── site.css ├── site.scss └── site ├── _normalize.scss └── _site.scss /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | "@babel/env" 4 | ] 5 | } 6 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # EditorConfig is awesome: http://EditorConfig.org 2 | 3 | # top-most EditorConfig file 4 | root = true 5 | 6 | # Unix-style newlines with a newline ending every file 7 | [*] 8 | end_of_line = lf 9 | insert_final_newline = true 10 | 11 | # trim_trailing_whitespace = true NIGEL TO DO - Needed??? 12 | 13 | indent_style = space 14 | indent_size = 2 15 | 16 | # Matches multiple files with brace expansion notation 17 | # Set default charset 18 | [*.{js,html}] 19 | charset = utf-8 20 | 21 | # 2 space indentation 22 | [*.{js,html,css,scss}] 23 | indent_style = space 24 | indent_size = 2 25 | 26 | # Tab indentation (no size specified) 27 | [Makefile] 28 | indent_style = tab 29 | 30 | # Indentation override for all JS under lib directory 31 | [lib/**.js] 32 | indent_style = space 33 | indent_size = 2 34 | 35 | # Matches the exact files either package.json or .travis.yml 36 | [{package.json,.travis.yml}] 37 | indent_style = space 38 | indent_size = 2 39 | 40 | # Markdown files 41 | [*.md] 42 | trim_trailing_whitespace = false 43 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Dependencies 2 | node_modules 3 | 4 | # Compiled output 5 | /dist 6 | /.tmp 7 | /zip 8 | 9 | # System Files 10 | .DS_Store 11 | Thumbs.db 12 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2017 Nigel O Toole 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Direction Reveal 2 | ### A plugin that detects the direction a user enters or leaves an element allowing you to reveal or hide content based on this direction. 3 | 4 | ### [View demo](http://nigelotoole.github.io/direction-reveal/) 5 | 6 | 7 | 8 | ## Installation 9 | ```javascript 10 | $ npm install direction-reveal --save-dev 11 | ``` 12 | 13 | 14 | ## Usage 15 | 16 | ### Import JS 17 | 18 | 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. 19 | 20 | ```javascript 21 | import DirectionReveal from 'direction-reveal'; 22 | 23 | // Init with default setup 24 | const directionRevealDemo = DirectionReveal(); 25 | 26 | // Init with all options at default setting 27 | const directionRevealDefault = DirectionReveal({ 28 | selector: '.direction-reveal', 29 | itemSelector: '.direction-reveal__card', 30 | animationName: 'swing', 31 | animationPostfixEnter: 'enter', 32 | animationPostfixLeave: 'leave', 33 | enableTouch: true, 34 | touchThreshold: 250 35 | }); 36 | ``` 37 | 38 | ### Options 39 | | Property | Default | Type | Description | 40 | | ----------------------- | --------------------------- | ---------- | ------------------------------------------------------------------------------------------------- | 41 | | `selector` | '.direction-reveal' | String | Container element selector. | 42 | | `itemSelector` | '.direction-reveal\_\_card' | String | Item element selector. | 43 | | `animationName` | 'swing' | String | Animation class. | 44 | | `animationPostfixEnter` | 'enter' | String | Animation CSS class postfix for enter event. | 45 | | `animationPostfixLeave` | 'leave' | String | Animation CSS class postfix for leave event. | 46 | | `enableTouch` | true | Boolean | Adds touch event to show content on first click then follow link on the second click. | 47 | | `touchThreshold` | 250 | Number(ms) | The touch length in ms to trigger the reveal, this is to prevent triggering if user is scrolling. | 48 | 49 | 50 | ### Import SASS 51 | 52 | ```scss 53 | @import "node_modules/direction-reveal/src/styles/direction-reveal.scss"; 54 | ``` 55 | 56 | 57 | ### Markup 58 | 59 | ```html 60 |
568 | $ npm install direction-reveal --save-dev
569 |
570 |
571 | 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.
580 | 581 |import DirectionReveal from 'direction-reveal';
582 |
583 | // Init with default setup
584 | const directionRevealDemo = DirectionReveal();
585 |
586 | // Init with all options at default setting
587 | const directionRevealDefault = DirectionReveal({
588 | selector: '.direction-reveal',
589 | itemSelector: '.direction-reveal__card',
590 | animationName: 'swing',
591 | animationPostfixEnter: 'enter',
592 | animationPostfixLeave: 'leave',
593 | enableTouch: true,
594 | touchThreshold: 250
595 | });
596 |
597 |
598 | Property | 604 |Default | 605 |Type | 606 |Description | 607 |
---|---|---|---|
selector |
610 | '.direction-reveal' | 611 |String | 612 |Container element selector. | 613 |
itemSelector |
616 | '.direction-reveal__card' | 617 |String | 618 |Item element selector. | 619 |
animationName |
622 | 'swing' | 623 |String | 624 |Animation class. | 625 |
animationPostfixEnter |
628 | 'enter' | 629 |String | 630 |Animation CSS class postfix for enter event. | 631 |
animationPostfixLeave |
634 | 'leave' | 635 |String | 636 |Animation CSS class postfix for leave event. | 637 |
enableTouch |
640 | true | 641 |Boolean | 642 |Adds touch event to show content on first click then follow link on the second click. | 643 |
touchThreshold |
646 | 250 | 647 |Number(ms) | 648 |The touch length in ms to trigger the reveal, this is to prevent triggering if user is scrolling. | 649 |
@import "node_modules/direction-reveal/src/styles/direction-reveal.scss";
657 |
658 |
659 | <div class="direction-reveal">
662 |
663 | <a href="#" class="direction-reveal__card">
664 | <img src="images/image.jpg" class="direction-reveal__img">
665 |
666 | <div class="direction-reveal__overlay direction-reveal__anim--enter">
667 | <h3 class="direction-reveal__title">Title</h3>
668 | <p class="direction-reveal__text">Description text.</p>
669 | </div>
670 | </a>
671 |
672 | ...
673 |
674 | </div>
675 |
676 |
677 |
678 | The demos use <a> tags for the "direction-reveal__card" but <div> tags 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.
681 | 682 |<div class="direction-reveal__card" tabindex="0">
683 | ...
684 | </div>
685 |
686 |
687 |
688 | 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.
691 | 692 |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.
693 | 694 |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).
700 | 701 |document.querySelector('#test').addEventListener('directionChange', (event) => {
702 | console.log(`Action: ${event.detail.action} Direction: ${event.detail.direction}`);
703 | });
704 |
705 | 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.
713 | 714 |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.
717 |Clone or download from Github.
722 | 723 |$ npm install
724 | $ gulp serve
725 |
726 |
727 | Inspired by a Codepen by Noel Delgado, this Stack overflow answer, the article Get an Element's position using javascript and
images from Unsplash.