- hide() { this.toggle(false); }
- show() { this.toggle(true); }
-
- toggle(show = true) {
- let start = Date.now();
- let duration = 240;
-
- function setOpacity() {
- let elapsedTime = (Date.now() - start);
- let targetOpacity = show ? (elapsedTime / duration) : 1-(elapsedTime / duration);
- this.container.style.opacity = targetOpacity;
- if (elapsedTime > duration) {
- this.container.style.display = show ? 'flex' : 'none';
- if (show) {
- this.focusOnBody();
- }
- this.container.style.opacity = '';
- } else {
- requestAnimationFrame(setOpacity.bind(this));
- }
- }
+ hide(onComplete = null) { this.toggle(false, onComplete); }
+ show(onComplete = null) { this.toggle(true, onComplete); }