<div class="search-form">
<form>
<input type="text">
<button></button>
</form>
</div>
* {
outline: none;
border: none;
padding: 0;
}
body {
background-color: rgb(71, 136, 135);
}
.search-form {
position: relative;
margin: 150px auto 0;
width: 300px;
}
.search-form:before {
content: ' ';
position: absolute;
left: 25px;
top: 14px;
width: 2px;
height: 36px;
transform: scale(0);
z-index: 1;
background: rgb(71, 136, 135);
transition: all 0.5s cubic-bezier(.87, -.41, .19, 1.44);
}
.active:before {
transform: scale(1);
transition-delay: 0.3s;
animation: 0.6s cubic-bezier(.87, -.41, .19, 1.44) 0.5s infinite forwards focus;
}
input {
border-radius: 36px;
position: absolute;
width: 64px;
height: 64px;
transition: all 0.5s cubic-bezier(.87, -.41, .19, 1.44);
}
.active input {
width: 100%;
padding-left: 25px;
border-radius: 36px;
}
button {
background: rgba(255, 255, 255, 1);
position: absolute;
height: 100%;
border-radius: 50%;
width: 64px;
height: 64px;
transition: all 0.5s cubic-bezier(.87, -.41, .19, 1.44);
}
button:after {
content: ' ';
position: absolute;
width: 32px;
height: 32px;
left: 0;
right: 0;
transform: translateY(-50%);
margin: 0 auto;
background: rgb(254, 111, 117);
border-radius: 50%;
}
button:before {
content: ' ';
position: absolute;
width: 24px;
height: 24px;
left: 0;
right: 0;
top: 20px;
transform: scale(0);
transform-origin: left top;
margin: 0 auto;
background: white;
border-radius: 50%;
z-index: 1;
transition: all 0.8s ease;
}
.active button {
transform: translateX(260px);
}
.active button:before {
transform: scale(1);
}
.focus:before {
transform: scale(0);
animation: none;
}
@keyframes focus {
0 {
opacity: 0;
}
50% {
opacity: 1;
}
100% {
opacity: 0;
}
}
var input = document.querySelector('.search-form');
var search = document.querySelector('input')
var button = document.querySelector('button');
button.addEventListener('click', function(e) {
e.preventDefault();
input.classList.toggle('active');
})
search.addEventListener('focus', function() {
input.classList.add('focus');
})
search.addEventListener('blur', function() {
search.value.length != 0 ? input.classList.add('focus') : input.classList.remove('focus');
})
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.