Skip to content
Snippets Groups Projects
Commit d11e4e71 authored by Olivia206's avatar Olivia206
Browse files

fix js

parent 6f9a7621
No related branches found
No related tags found
No related merge requests found
......@@ -11,15 +11,14 @@ class Modal {
this.id = this.button.getAttribute('data-open-modal');
this.element = document.getElementById(this.id);
this.closeButtons = this.element.querySelectorAll('.close');
this.state = {
opened: false
}
if (!this.element) {
return;
}
this.state = {
isOpened: false
};
this.listen();
}
......@@ -51,17 +50,25 @@ class Modal {
});
}
toggle(open = !this.state.isOpened) {
this.state.isOpened = open;
const classAction = this.state.isOpened ? 'add' : 'remove';
let transitionDuration = window.getComputedStyle(this.element).transitionDuration;
transitionDuration = parseFloat(transitionDuration.replace('s', ''));
toggle(open) {
this.state.opened = typeof open !== 'undefined' ? open : !this.state.opened;
const classAction = this.state.opened ? 'add' : 'remove',
transitionDuration = this.state.opened ? 0 : this.getTransitionDuration();
this.element.setAttribute('aria-hidden', !this.state.isOpened);
document.documentElement.classList[classAction](CLASSES.modalOpened);
setTimeout(() => {
this.element.setAttribute('aria-hidden', !this.state.opened);
this.element.classList[classAction](CLASSES.modalIsOpened);
}, transitionDuration * 1000);
setTimeout(() => {
document.documentElement.classList[classAction](CLASSES.modalOpened);
}, 50);
}
getTransitionDuration () {
let transitionDuration = window.getComputedStyle(this.element).transitionDuration;
transitionDuration = parseFloat(transitionDuration.replace('s', ''));
return transitionDuration;
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment