├── .gitignore ├── LICENSE ├── README.md ├── min └── delighters.min.js └── src ├── delighters.js ├── index.html └── style.css /.gitignore: -------------------------------------------------------------------------------- 1 | /node_modules 2 | gruntfile.js 3 | package-lock.json 4 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Q42 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 | Delighters 2 | ========== 3 | 4 | Add CSS animations to delight users as they scroll down. 5 | A tiny javascript library by [Q42](https://q42.com). 6 | It was written by [Martin Kool](https://twitter.com/mrtnkl). 7 | 8 | See the demo [here](https://q42.github.io/delighters) 9 | 10 | Usage 11 | --- 12 | 1. Include the script. 13 | ``` js 14 | 8 | 9 | 10 |
11 |
12 |

Delighters.JS

13 |

Add CSS animations to delight users as they scroll down.

14 |

15 | A tiny javascript library by Q42
16 | https://github.com/Q42/delighters 17 |

18 |
19 |
20 |
1. Include the script
21 |
2. Add data-delighter attributes
22 |
3. Write your own CSS delighters
23 |
24 |
25 |

Features

26 | 34 |
35 |
36 |

Usage

37 |

1. Include the script

38 |
 39 |    <script type="text/javascript" src="delighters.js">
40 |

2. Add delighter attributes

41 |
 42 |    <div class="foo" data-delighter>
43 |

44 | 3. Style the delighter (or its children) using built-in classes 45 | .started and .ended 46 |

47 |
 48 |    /* when the library loads, each [data-delighter] 
 49 |       gets the .delighter class */
 50 | 
 51 |    .foo.delighter {
 52 |       transition: all .3s ease-out;
 53 |       transform: translateX(-100%);
 54 |       opacity: 0;
 55 |    }
 56 | 
 57 |    /* the .started class is set when the top
 58 |       of [data-delighter] is at 0.75 of the viewport 
 59 |       (where 0 is top and 1 is bottom) */
 60 | 
 61 |    .foo.delighter.started {
 62 |       transform: none;
 63 |       opacity: 1;
 64 |    }
 65 | 
 66 |    /* an extra .ended state is set when the bottom 
 67 |       of [data-delighter] is at 0.75 of the viewport
 68 |       (where 0 is top and 1 is bottom) */
 69 | 
 70 |    .foo.delighter.started.ended {
 71 |       border: solid red 10px;
 72 |    }
73 |
74 |
75 |

How it works

76 | 84 |
85 |
86 |

Debugging

87 | 94 |
95 |
96 |

Customizing

97 |

98 | By default, delighters.js intializes automatically when the DOM is ready, and with the following configuration: 99 |

100 |
101 |   options = {
102 |     attribute:  'data-delighter',
103 |     classNames: ['delighter', 'started', 'ended'],
104 |     start:      0.75, // default start threshold
105 |     end:        0.75, // default end threshold
106 |     autoInit:   true  // initialize when DOMContentLoaded
107 |   }
108 |

109 | You can customize any or all of the above properties using: 110 |

111 |   Delighters.config({    
112 |     // set the default start threshold at the bottom
113 |     start: 1,
114 |     // let's call Delighters.init() manually later
115 |     autoInit: false 
116 |     // ... etc ...
117 |   })
118 |
119 |
120 |

Enjoy!

121 |
122 |
123 | 124 | -------------------------------------------------------------------------------- /src/style.css: -------------------------------------------------------------------------------- 1 | html, body { 2 | margin: 0; 3 | } 4 | article { 5 | font-size: 2em; 6 | font-family: futura, sans-serif; 7 | overflow-x: hidden; 8 | } 9 | @media (max-width: 460px) { 10 | article { 11 | font-size: 1.5em; 12 | } 13 | } 14 | section { 15 | position: relative; 16 | padding: 10vh 10vw; 17 | min-height: 100vh; 18 | color: #333; 19 | } 20 | section:nth-child(odd) { 21 | background: #4dc6e6; 22 | color: #fff; 23 | } 24 | section:nth-child(3) { background: #0aba58; color: #fff; } 25 | section:nth-child(4) { background: #f8c82d; color: #333; } 26 | pre { 27 | font-size: .75em; 28 | background: #222; color: #fff; 29 | padding: 20px; 30 | } 31 | .box { 32 | position: relative; 33 | width: 50%; height: 30vh; 34 | background: #ec484d; margin: 10px; box-shadow: 0 0 10px rgba(0,0,0,.3); 35 | text-align: center; 36 | color: #fff; 37 | font-size: 0.8em; 38 | padding: 10px; 39 | } 40 | .box:nth-child(2) { background: #f8c82d; } 41 | .box:nth-child(3) { background: #0aba58; } 42 | a { 43 | color: inherit; 44 | } 45 | 46 | .delighter.splash { 47 | transition: all 2s ease-out; 48 | } 49 | .delighter.splash.ended { 50 | background: #fff; 51 | } 52 | .delighter.right { transform:translate(-100%); opacity:0; transition: all .75s ease-out; } 53 | .delighter.right.started { transform:none; opacity:1; } 54 | 55 | .delighter.left { transform:translate(100%); opacity:0; transition: all .75s ease-out; } 56 | .delighter.left.started { transform:none; opacity:1; } 57 | 58 | .delighter.bottom { transform:translatey(300%); opacity:0; transition: all .75s ease-out; } 59 | .delighter.bottom.started { transform:none; opacity:1; } 60 | 61 | .delighter li { opacity: 0; transform: translatey(400%); transition: all .7s ease-out; } 62 | .delighter.started li { opacity: 1; transform: none; } 63 | .delighter.started li:nth-child(1) { transition: all .7s ease-out .1s; } 64 | .delighter.started li:nth-child(2) { transition: all .7s ease-out .3s; } 65 | .delighter.started li:nth-child(3) { transition: all .7s ease-out .5s; } 66 | .delighter.started li:nth-child(4) { transition: all .7s ease-out .7s; } 67 | .delighter.started li:nth-child(5) { transition: all .7s ease-out .9s; } 68 | .delighter.started li:nth-child(6) { transition: all .7s ease-out 1.1s; } 69 | .delighter.started li:nth-child(7) { transition: all .7s ease-out 1.3s; } 70 | 71 | .delighter pre { 72 | display: block; transition: all 2s ease-out; opacity: 0; 73 | padding: 20px 0; 74 | width: 1px; overflow: hidden; 75 | } 76 | .delighter.started pre { 77 | max-width: 99999px; width: 100%; opacity: 1; 78 | } 79 | .delighter .box { transition: all 1s ease-out; } 80 | .delighter .box:nth-child(1) { transform: translate(-100%, 0); } 81 | .delighter .box:nth-child(2) { transform: translate(170%, -70%); } 82 | .delighter .box:nth-child(3) { transform: translate(20%, 0%); } 83 | 84 | .delighter.started .box:nth-child(1) { transform: translate(0, 0); } 85 | .delighter.started .box:nth-child(2) { transform: translate(70%, -70%); } 86 | .delighter.started .box:nth-child(3) { transform: translate(20%, -120%); } 87 | 88 | --------------------------------------------------------------------------------