Shit slider
First shit slider
HTML
<script src="https://cdnjs.cloudflare.com/ajax/libs/hammer.js/2.0.8/hammer.min.js"></script>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" href="/style.css">
<title>Document</title>
</head>
<body>
<a href='#' class='modal_link' id='m1'>form 1</a>
<a href='#' class='modal_link' id='m2'>form 2</a>
<div class='m1 modal'>
<p>form 1</p>
<form method="post" action="form.php">
<input type="text" name="name" required>
<input type="email" name="email" required>
<button type="submit">Отправить</button>
</form>
</div>
<div class='m2 modal'>
<p>form 2</p>
<form method="post" action="form.php">
<input type="text" name="name2" required>
<input type="email" name="email2" required>
<button type="submit">Отправить</button>
</form>
</div>
<script src="/script.js"></script>
</body>
</html>
CSS
body {
margin: 0;
padding: 0px;
}
* {
box-sizing: border-box;
}
.modal {
position: fixed;
display: block;
background: #ccc;
max-width: 600px;
margin-top: 10%;
min-width: 260px;
transform: translateY(-900px) scale(0.1,0.2);
transition: 0.5s;
text-align: center;
opacity: 0;
box-sizing: border-box;
padding: 20px;
}
JavaScript
var els = document.getElementsByClassName('modal_link');
for(var i in els){
els[i].addEventListener('click', function(e) {
tabcontent = document.getElementsByClassName(" modal");
for (i = 0; i < tabcontent.length; i++) {
tabcontent[i].style.transform = "translateY(-900px) scale(0.1,0.2)";
tabcontent[i].style.opacity = "0";
};
var el = this.getAttribute('id');
var el_box = document.querySelector('.'+el);
el_box.style.marginLeft = 'calc(50% - '+(el_box.offsetWidth / 2)+'px)';
el_box.style.marginRight = 'calc(50% - '+(el_box.offsetWidth / 2)+'px)';
el_box.style.transform = "translateX(0px) scale(1,1)";
el_box.style.opacity = "1";
});
};