JSFiddle - React, Tailwind, and code Playground
by mtenschert
HTML
<div id="searchform-container" class="searchform-overlay">
<div class="close-btn">X</div>
<div class="searchform-overlay-inner">
<div class="searchform-wrapper">
<form id="search-form" class="search-form" accept-charset="UTF-8" method="post" action="/search/node">
<input type="text" />
<input type="button" value="search" />
</form>
</div>
</div>
</div>
<div id="block-block-3">
<p id="open">click to open search overlay</p>
</div>
CSS
#block-block-3 {
float: left;
}
.searchform-overlay {
background-color: rgba(255, 255, 255, 0.95);
bottom: 0;
display: table;
height: 100%;
left: 0;
opacity: 0;
position: fixed;
right: 0;
top: 0;
transition: opacity 0.3s ease-in-out 0s, visibility 0.3s ease-in-out 0.3s;
visibility: hidden;
width: 100%;
z-index: 9999;
}
.searchform-overlay.header-search-active {
opacity: 1;
transition-delay: 0s;
visibility: visible;
}
.searchform-overlay .searchform-overlay-inner {
display: table-cell;
text-align: center;
vertical-align: middle;
}
.searchform-overlay .searchform-overlay-inner .searchform-wrapper {
color: #36353c;
font-size: 30px;
margin: 0 auto;
max-width: 1000px;
text-align: center;
}
.close-btn {
border: 2px solid #818181;
border-radius: 92px;
color: #818181;
cursor: pointer;
font-family: cursive;
font-size: x-large;
height: 30px;
padding: 0 7px 7px;
position: absolute;
right: 61px;
text-align: center;
top: 50px;
width: 30px;
}
JavaScript
$(document).ready(function () {
//Search
$("#block-block-3 p").click(function () {
$(".searchform-overlay").addClass("header-search-active");
});
$(".close-btn").click(function () {
$(".searchform-overlay").removeClass("header-search-active");
});
$(document).click(function (e) {
if ($(".searchform-overlay").hasClass("header-search-active")) {
if (!$('#search-form').is(e.target) && !$('input').is(e.target) && !$('#open').is(e.target)) {
$(".searchform-overlay").removeClass("header-search-active");
}
}
});
});