Skip to content

Instantly share code, notes, and snippets.

@emelent
Created December 12, 2016 16:35
Show Gist options
  • Save emelent/73f73c3c3ef3c85f73cdc9898426af06 to your computer and use it in GitHub Desktop.
Save emelent/73f73c3c3ef3c85f73cdc9898426af06 to your computer and use it in GitHub Desktop.
Search Box
<div class="searchbox" onClick="onClick(event)">
<input type="text" onFocus="onFocus()" onBlur="onBlur()"/>
<button>
<i class="fa fa-search" aria-hidden="true"></i>
</button>
</div>
function activateSearchbox(el){
el.classList.add('searchbox--active')
}
function deactivateSearchbox(el){
el.classList.remove('searchbox--active')
}
function onFocus(){
activateSearchbox(document.querySelector('.searchbox'));
}
function onBlur(){
deactivateSearchbox(document.querySelector('.searchbox'));
}
html{
box-size: border-box;
background: #2196F3;
}
*, *:before, *:after{
box-sizing: inherit;
}
*, *:active, *:focus{
outline: none;
}
$btn-width: 44px;
.searchbox{
position: relative;
height: 40px;
width: 400px;
margin: 50px auto;
overflow: hidden;
border-bottom: 2px solid #fff;
background: none;
color: #fff;
perspective: 1800px;
perspective-origin: 40% 40%;
transform-style: preserve-3d;
transition: all 0.4s cubic-bezier(.25, .8, .25, 1);
&--active{
color: #000;
}
&:after{
position: absolute;
content: "";
// z-index: 1;
width: 100%;
height: 100%;
top: 20px;
left: 0px;
transform: rotateX(90deg);
background: #fff;
transition: all 0.4s cubic-bezier(.25, .8, .25, 1);
}
&--active:after{
top: 0px;
left: 0px;
transform: rotateX(0deg);
}
input{
position: absolute;
z-index: 1;
height: 100%;
width: 100%;
padding-left: 8px;
padding-right: $btn-width;
border: none;
font-size: 1em;
color: inherit;
background: none;
}
button{
position: absolute;
z-index: 1;
right: 0px;
top: 0px;
height: 100%;
width: $btn-width;
border: none;
background: none;
font-size: 1.4em;
color: inherit;
}
}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment