input with animation
by youssef moudine
HTML
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"></script>
<div id="inupt-container">
<input type="text" placeholder="Search...">
<div id="btn-add"></div>
<div id="message">a name is required</div>
</div>
CSS
#inupt-container{
outline: 1px dashed red!important;
position:relative;
width: 300px;
height: 40px;
}
#btn-add{
position:absolute;
top: 0;
right: 0;
width: 40px;
height: 40px;
background: crimson;
border-radius: 50%;
transition: all 1s;
z-index: 4;
box-shadow: 0 0 25px 0 rgba(0, 0, 0, 0.4);
}
#btn-add:hover {
cursor: pointer;
}
#btn-add::before {
content: "";
position: absolute;
margin: auto;
top: 22px;
right: 0;
bottom: 0;
left: 22px;
width: 12px;
height: 2px;
background: white;
transform: rotate(45deg);
transition: all .5s;
}
#btn-add::after {
content: "";
position: absolute;
margin: auto;
top: -5px;
right: 0;
bottom: 0;
left: -5px;
width: 25px;
height: 25px;
border-radius: 50%;
border: 2px solid white;
transition: all .5s;
}
input {
font-family: 'Inconsolata', monospace;
position:absolute;
top: 5px;
right: 0;
width: 30px;
height: 30px;
outline: none;
border: none;
background: crimson;
color: white;
text-shadow: 0 0 10px crimson;
padding: 0 45px 0 15px;
border-radius: 30px;
box-shadow: 0 0 25px 0 crimson, 0 20px 25px 0 rgba(0, 0, 0, 0.2);
transition: all 1s;
opacity: 0;
z-index: 5;
font-weight: bolder;
letter-spacing: 0.1em;
}
input:hover {
cursor: pointer;
}
input.active {
width: 240px;
opacity: 1;
cursor: text;
}
#btn-add.active {
background: black;
z-index: 6;
}
#btn-add.active ::before {
top: 8px;
left: -13px;
width: 9px;
background: blue;
}
input:focus ~ #btn-add::after {
top: 0px;
left: 5px;
width: 20px;
height: 2px;
border: none;
background: blue;
border-radius: 0%;
transform: rotate(-45deg);
}
input::placeholder {
color: white;
opacity: 0.5;
font-weight: bolder;
}
JavaScript
let btn = $('#btn-add');
let input = $('#inupt-container input');
btn.on('click', e => {
if(btn.hasClass('active')){
console.log('hide');
btn.removeClass('active');
input.removeClass('active');
}else{
console.log('show');
btn.addClass('active');
input.addClass('active');
}
})