JSFiddle - React, Tailwind, and code Playground
by Marcos vini
HTML
<div for="modal" class="modal-bg none"></div>
<div class="modal-content">
<header><h2>teste</h2></header>
<article class="content none">
xxxxxx
</article>
<footer>
<a class="fechar button danger">Fechar</a>
</footer>
</div>
<button data-modal='edit-episodio'>
Open
</button>
CSS
.none{
display:none;
}
.modal-bg {
z-index: 99;
visibility: visible;
background-color: black;
opacity: 0.7;
transition: background-color 250ms linear;
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 1000%;
}
.modal-content {
position: fixed;
top: 50%;
left: 50%;
width: 50%;
height: auto;
margin-top: -18%;
margin-left: -25%;
padding: 10px;
background-color: white;
border-radius: 4px;
box-shadow: 0 0 50px rgba(0, 0, 0, 0.5);
visibility: visible;
transform: scale(1);
transition: transform 250ms ease;
z-index: 9999;
}
.modal-content > header {
background: #58543d;
padding: 0;
position: relative;
display: block;
border-bottom: 1px solid #eee;
}
.modal-content > header:before, .modal-content > header:after {
display: table;
content: " ";
clear: both;
}
.modal-content header h2 {
padding: 0;
font-size: 25px;
font-family: Raleway, arial, sans-serif;
margin: 0;
color: #fff;
text-align: center;
line-height: 20px;
width: 100%;
border: 0;
padding-top: 15px;
}
.modal-content footer {
position: relative;
display: flex;
align-items: center;
justify-content: center;
width: 100%;
margin: 0;
padding: 10px 0 10px;
}
.modal-content footer .button {
position: relative;
padding: 10px 30px;
border-radius: 3px;
font-size: 14px;
font-weight: 400;
color: white;
text-transform: uppercase;
overflow: hidden;
background-color: #e74c3c;
text-decoration: none;
}
JavaScript
var modal_bg = document.querySelector('.modal-bg');
var modal_container = document.querySelector('.modal-content');
function eventmodal(){
if(modal_container.classList.contains("none")){
modal_container.classList.remove('none');
modal_bg.classList.remove('none');
}else{
modal_container.classList.add('none');
modal_bg.classList.add('none');
}
}
document.querySelector('button[data-modal="edit-episodio"]').addEventListener("click",function(){
eventmodal();
});
document.querySelector('footer .fechar').addEventListener("click",function(){
eventmodal();
});