|
1 |
| -import anim from "animejs"; |
2 |
| - |
3 | 1 | import { Utils } from "./utils";
|
4 | 2 | import { Component, BaseOptions, InitElements, MElement } from "./component";
|
5 | 3 |
|
@@ -144,64 +142,33 @@ export class Collapsible extends Component<CollapsibleOptions> {
|
144 | 142 | }
|
145 | 143 |
|
146 | 144 | _animateIn(index: number) {
|
147 |
| - const li = this.el.children[index]; |
| 145 | + const li = <HTMLLIElement>this.el.children[index]; |
148 | 146 | if (!li) return;
|
149 | 147 | const body: HTMLElement = li.querySelector('.collapsible-body');
|
150 |
| - anim.remove(body); |
151 | 148 | body.style.display = 'block';
|
152 |
| - body.style.overflow = 'hidden'; |
153 |
| - body.style.height = '0'; |
154 |
| - body.style.paddingTop = ''; |
155 |
| - body.style.paddingBottom = ''; |
156 |
| - const pTop = getComputedStyle(body).paddingTop; // . css('padding-top'); |
157 |
| - const pBottom = getComputedStyle(body).paddingBottom; //body.css('padding-bottom'); |
158 |
| - const finalHeight = body.scrollHeight; |
159 |
| - body.style.paddingTop = '0'; |
160 |
| - body.style.paddingBottom = '0'; |
161 |
| - anim({ |
162 |
| - targets: body, |
163 |
| - height: finalHeight, |
164 |
| - paddingTop: pTop, |
165 |
| - paddingBottom: pBottom, |
166 |
| - duration: this.options.inDuration, |
167 |
| - easing: 'easeInOutCubic', |
168 |
| - complete: (anim) => { |
169 |
| - body.style.overflow = ''; |
170 |
| - body.style.height = ''; |
171 |
| - body.style.paddingTop = ''; |
172 |
| - body.style.paddingBottom = ''; |
173 |
| - // onOpenEnd callback |
174 |
| - if (typeof this.options.onOpenEnd === 'function') { |
175 |
| - this.options.onOpenEnd.call(this, li); |
176 |
| - } |
| 149 | + body.style.maxHeight = '0'; |
| 150 | + const duration = this.options.inDuration; // easeInOutCubic |
| 151 | + body.style.transition = `max-height ${duration}ms ease-out`; |
| 152 | + body.style.maxHeight = body.scrollHeight + "px"; |
| 153 | + setTimeout(() => { |
| 154 | + if (typeof this.options.onOpenEnd === 'function') { |
| 155 | + this.options.onOpenEnd.call(this, li); |
177 | 156 | }
|
178 |
| - }); |
| 157 | + }, duration); |
179 | 158 | }
|
180 | 159 |
|
181 | 160 | _animateOut(index: number) {
|
182 | 161 | const li = this.el.children[index];
|
183 | 162 | if (!li) return;
|
184 | 163 | const body: HTMLElement = li.querySelector('.collapsible-body');
|
185 |
| - anim.remove(body); |
186 |
| - body.style.overflow = 'hidden'; |
187 |
| - anim({ |
188 |
| - targets: body, |
189 |
| - height: 0, |
190 |
| - paddingTop: 0, |
191 |
| - paddingBottom: 0, |
192 |
| - duration: this.options.outDuration, |
193 |
| - easing: 'easeInOutCubic', |
194 |
| - complete: () => { |
195 |
| - body.style.overflow = ''; |
196 |
| - body.style.height = ''; |
197 |
| - body.style.padding = ''; |
198 |
| - body.style.display = ''; |
199 |
| - // onCloseEnd callback |
200 |
| - if (typeof this.options.onCloseEnd === 'function') { |
201 |
| - this.options.onCloseEnd.call(this, li); |
202 |
| - } |
| 164 | + const duration = this.options.outDuration; // easeInOutCubic |
| 165 | + body.style.transition = `max-height ${duration}ms ease-out`; |
| 166 | + body.style.maxHeight = "0"; |
| 167 | + setTimeout(() => { |
| 168 | + if (typeof this.options.onCloseEnd === 'function') { |
| 169 | + this.options.onCloseEnd.call(this, li); |
203 | 170 | }
|
204 |
| - }); |
| 171 | + }, duration); |
205 | 172 | }
|
206 | 173 |
|
207 | 174 | /**
|
|
0 commit comments