├── .gitignore ├── .npmignore ├── README.md ├── dist ├── index.js ├── index.js.map ├── index.mjs ├── index.mjs.map ├── index.umd.js └── index.umd.js.map ├── package-lock.json ├── package.json └── source ├── css-transition.js ├── ease.js └── index.js /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | .DS_Store 3 | .cache -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | .cache 2 | source -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |
35 | ![]() |
37 |
38 | Basic usage39 | 40 | ```js 41 | import { cssTransition, ease } from 'css-transit' 42 | 43 | const element = document.querySelector('.element') 44 | 45 | cssTransition(element, 500, { 46 | transform: 'translate(200px, 200px) scale(1)', 47 | }) 48 | ``` 49 | 50 | |
51 |
55 | ![]() |
57 |
58 | Easing59 | 60 | ```js 61 | cssTransition(element, 500, { 62 | transform: 'translate(0, 0) scale(1.5)', 63 | }, { 64 | transform: 'translate(200px, 200px) scale(1)', 65 | ease: ease.inOutQuint 66 | }) 67 | ``` 68 | `css-transit` comes with the standard easing functions. 69 | 70 | You can also supply your own `cubic-bezier`: 71 | ```js 72 | cssTransition(element, 500, { 73 | opacity: 1, 74 | ease: 'cubic-bezier(0.540, 0.745, 0.230, 0.765)' 75 | } 76 | ``` 77 | 78 | |
79 |
83 | ![]() |
85 |
86 | Showing / Hiding87 | 88 | ```js 89 | cssTransition(thing, 500, { 90 | opacity: 0, 91 | transform: 'translate(80px, 100px) scale(1.3) rotate(40deg)', 92 | display: 'none' 93 | }) 94 | ``` 95 | 96 | `display` props will be applied after the transition finishes, to allow easy hiding of elements. 97 | 98 | |
99 |
103 | ![]() |
105 |
106 | Staggering107 | 108 | ```js 109 | // first convert the NodeList to an Array 110 | const elements = [...document.querySelectorAll('.thing')] 111 | 112 | cssTransition(elements, 500, { 113 | transform: 'translate(0, 0)', 114 | }, { 115 | transform: 'translate(0, 200px)', 116 | ease: ease.inOutQuart 117 | }, 50) 118 | ``` 119 | 120 | When transitioning multiple items, the last argument can be used to stagger the animations (this adds a `transition-delay`). 121 | 122 | |
123 |
127 | ![]() |
129 |
130 | Callbacks / Promises131 | 132 | ```js 133 | function loop() { 134 | cssTransition(elements, 500, { 135 | transform: 'translate(0, 200px) scaleY(.4) scaleX(.2) rotate(180deg)', 136 | ease: ease.inOutQuart 137 | }, 100) 138 | .then(() => 139 | cssTransition(elements, 500, { 140 | transform: 'rotate(360deg)', 141 | ease: ease.inOutQuart, 142 | clearStyle: true 143 | }, 100) 144 | ) 145 | .then(loop) 146 | } 147 | 148 | loop() 149 | ``` 150 | 151 | `cssTransition` returns a `Promise` that is resolved when the animation has finished. 152 | When transitioning multiple elements, the `Promise` is resolved when the transition of the _last_ element finishes. 153 | 154 | |
155 |
159 | ![]() |
161 |
162 | Function props163 | 164 | ```js 165 | cssTransition([...thing], 500, { 166 | transform: (el, i) => `translate(0, ${(i+1) * 40}px)`, 167 | ease: ease.inOutQuart 168 | }, 100) 169 | ``` 170 | 171 | `cssTransition 1.2.0+` allows you to use functions that returns a value as props. 172 | The first argument is the `element` being changed. 173 | The second argument is the `number` of the element in a staggered array. 174 | 175 | |
176 |