Как сделать плавное появление блока на нативном JavaScript-е? Чтобы было как в jQuery типа element.show(300).
Набросал лайт-код, но плавного появления мне добиться не удалось.
https://codepen.io/vlad-tarasoffka/pen/VwKweGb
<div class="container">
<a id="modal" href="#">Open modal</a>
<div class="overlay">
<div class="wrapper">
<div class="close">X</div>
<div class="text">
<h1>Uis facilis doloribus</h1>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Quis facilis doloribus esse dicta voluptate. Temporibus similique at ducimus ipsam magni. Quo, quasi explicabo? Impedit aliquam aperiam laudantium perferendis voluptas repudiandae!</p>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Quidem odit, perspiciatis ratione rem quasi sint non harum similique delectus quaerat.</p>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Nisi reiciendis non ipsum, quis quasi minus?</p>
</div>
<div class="modal-bottom"></div>
</div>
</div>
</div>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: Verdana;
}
.container {
width: 100%;
height: 100%;
padding: 25px;
background: #fff;
}
.overlay {
position: fixed;
display: none;
opacity: 0;
flex-direction: row;
justify-content: center;
align-items: center;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0,0,0,0.8);
}
.show {
display: flex;
opacity: 1;
transition: opacity 1s linear;
}
.wrapper {
position: relative;
display: flex;
flex-direction: column;
width: 60%;
height: 60%;
background: #fff;
border: 0;
box-shadow: 0 0 14px rgba(0,0,0,0.6);
}
.text {
height: 100%;
background: #fff;
border: none;
margin-top: 45px;
padding: 0 40px 30px 60px;
overflow-y: auto;
}
.close{
position: absolute;
width: 45px;
height: 45px;
top: 0;
right: 0;
background: #f00;
color: #fff;
font-weight: bold;
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
cursor: pointer;
}
.modal-bottom {
position: absolute;
width: calc(100% - 17px);
bottom: 0;
height: 50px;
background: linear-gradient(to top, #fff 35%, transparent);
}
h1 {
margin-bottom: 20px;
}
p {
line-height: 1.5;
margin-bottom: 10px;
}
const modalLink = document.querySelector('#modal');
const overlay = document.querySelector('.overlay');
const closeBtn = document.querySelector('.close');
modalLink.addEventListener('click', e => {
// overlay.style.display = 'flex';
overlay.classList.add('show');
});
closeBtn.addEventListener('click', e => {
// overlay.style.display = 'none';
overlay.classList.remove('show');
});