JSFiddle - React, Tailwind, and code Playground
HTML
<div class="info">
<div class="buttons">
<p>
<a href="#modal" data-modal="#modal" class="modal__trigger">Преимущества</a>
</p>
</div>
</div>
<!-- Modal -->
<div id="modal" class="modal modal__bg" role="dialog" aria-hidden="true">
<div class="modal__dialog">
<div class="modal__content">
<h1>Преимущества</h1>
<p>- Полный фотоотчет процесса ремонта и строительства</p>
<p>- Используем в работе свой транспорт, склады и специализированный инструмент</p>
<p>- На Вашем объекте инженеры с высшим образованием</p>
<p>- Гарантия чистоты после монтажных и демонтажных работ</p>
<!-- modal close button -->
<a href="" class="modal__close demo-close">
<svg class="" viewBox="0 0 24 24"><path d="M19 6.41l-1.41-1.41-5.59 5.59-5.59-5.59-1.41 1.41 5.59 5.59-5.59 5.59 1.41 1.41 5.59-5.59 5.59 5.59 1.41-1.41-5.59-5.59z"/><path d="M0 0h24v24h-24z" fill="none"/></svg>
</a>
</div>
</div>
</div>
<script>
</script>
<script>
</script>
CSS
/**
* Design bitoo.ru
*/
.modal {
will-change: visibility, opacity;
display: -webkit-box;
display: flex;
-webkit-box-align: center;
align-items: center;
-webkit-box-pack: center;
justify-content: center;
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
overflow-y: auto;
overflow-x: hidden;
z-index: 1000;
visibility: hidden;
opacity: 0;
-webkit-transition: all 0.5s cubic-bezier(0.23, 1, 0.32, 1);
transition: all 0.5s cubic-bezier(0.23, 1, 0.32, 1);
-webkit-transition-delay: $modal-delay;
transition-delay: $modal-delay;
}
.modal--active {
visibility: visible;
opacity: 1;
}
.modal--align-top {
-webkit-box-align: start;
align-items: flex-start;
}
.modal__bg {
background: transparent;
}
.modal__dialog {
max-width: 600px;
padding: 1.2rem;
}
.modal__content {
will-change: transform, opacity;
position: relative;
padding: 2.4rem;
background: #ffebee;
background-clip: padding-box;
box-shadow: 0 12px 15px 0 rgba(0,0,0,0.25);
opacity: 0;
-webkit-transition: all 0.25s cubic-bezier(0.23, 1, 0.32, 1);
transition: all 0.25s cubic-bezier(0.23, 1, 0.32, 1);
}
.modal__content--active {
opacity: 1;
}
.modal__close {
z-index: 1100;
cursor: pointer;
}
.modal__trigger {
position: relative;
display: inline-block;
padding: 1.2rem 2.4rem;
color: rgba(0,0,0,0.7);
line-height: 1;
cursor: pointer;
background: #ffebee;
box-shadow: 0 2px 5px 0 rgba(0,0,0,0.26);
-webkit-tap-highlight-color: rgba(0,0,0,0);
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
-webkit-transition: all 0.5s cubic-bezier(0.23, 1, 0.32, 1);
transition: all 0.5s cubic-bezier(0.23, 1, 0.32, 1);
}
.modal__trigger--active {
z-index: 10;
}
.modal__trigger:hover {
background: #e5d3d6;
}
#modal__temp {
will-change: transform, opacity;
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
background:...
JavaScript
var Modal = (function() {
var trigger = $qsa('.modal__trigger'); // what you click to activate the modal
var modals = $qsa('.modal'); // the entire modal (takes up entire window)
var modalsbg = $qsa('.modal__bg'); // the entire modal (takes up entire window)
var content = $qsa('.modal__content'); // the inner content of the modal
var closers = $qsa('.modal__close'); // an element used to close the modal
var w = window;
var isOpen = false;
var contentDelay = 400; // duration after you click the button and wait for the content to show
var len = trigger.length;
// make it easier for yourself by not having to type as much to select an element
function $qsa(el) {
return document.querySelectorAll(el);
}
var getId = function(event) {
event.preventDefault();
var self = this;
// get the value of the data-modal attribute from the button
var modalId = self.dataset.modal;
var len = modalId.length;
// remove the '#' from the string
var modalIdTrimmed = modalId.substring(1, len);
// select the modal we want to activate
var modal = document.getElementById(modalIdTrimmed);
// execute function that creates the temporary expanding div
makeDiv(self, modal);
};
var makeDiv = function(self, modal) {
var fakediv = document.getElementById('modal__temp');
/**
* if there isn't a 'fakediv', create one and append it to the button that was
* clicked. after that execute the function 'moveTrig' which handles the animations.
*/
if (fakediv === null) {
var div = document.createElement('div');
div.id = 'modal__temp';
self.appendChild(div);
moveTrig(self, modal, div);
}
};
var moveTrig = function(trig, modal, div) {
var trigProps = trig.getBoundingClientRect();
var m = modal;
var mProps = m.querySelector('.modal__content').getBoundingClientRect();
var transX, transY, scaleX, scaleY;
var xc = w.innerWidth / 2;
var yc = w.innerHeight...