Skip to content

Instantly share code, notes, and snippets.

@princekkk
Created October 6, 2019 12:52
Show Gist options
  • Save princekkk/1628dd4eee77f8c88812022c606db0f5 to your computer and use it in GitHub Desktop.
Save princekkk/1628dd4eee77f8c88812022c606db0f5 to your computer and use it in GitHub Desktop.
Search button animation
<div class="search">
<input type="search" class="search-box" />
<span class="search-button">
<span class="search-icon"></span>
</span>
</div>
$('.search-button').click(function(){
$(this).parent().toggleClass('open');
});
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
$background-color: #2A2E37;
$search-bg-color: #242628;
$icon-color: #00FEDE;
$transition: all .5s ease;
* {
box-sizing: border-box;
}
body {
background: $background-color;
}
.search {
width: 100px;
height: 100px;
margin: 40px auto 0;
background-color: $search-bg-color;
position: relative;
overflow: hidden;
transition: $transition;
&:before {
content: '';
display: block;
width: 3px;
height: 100%;
position: relative;
background-color: $icon-color;
transition: $transition;
}
&.open {
width: 420px;
&:before {
height: 60px;
margin: 20px 0 20px 30px;
position: absolute;
}
}
}
.search-box {
width: 100%;
height: 100%;
box-shadow: none;
border: none;
background: transparent;
color: #fff;
padding: 20px 100px 20px 45px;
font-size: 40px;
&:focus {
outline: none;
}
}
.search-button {
width: 100px;
height: 100px;
display: block;
position: absolute;
right: 0;
top: 0;
padding: 20px;
cursor: pointer;
}
.search-icon {
width: 40px;
height: 40px;
border-radius: 40px;
border: 3px solid $icon-color;
display: block;
position: relative;
margin-left: 5px;
transition: $transition;
&:before {
content: '';
width: 3px;
height: 15px;
position: absolute;
right: -2px;
top: 30px;
display: block;
background-color: $icon-color;
transform: rotate(-45deg);
transition: $transition;
}
&:after {
content: '';
width: 3px;
height: 15px;
position: absolute;
right: -12px;
top: 40px;
display: block;
background-color: $icon-color;
transform: rotate(-45deg);
transition: $transition;
}
.open & {
margin: 0;
width: 60px;
height: 60px;
border-radius: 60px;
&:before {
transform: rotate(52deg);
right: 22px;
top: 23px;
height: 18px;
}
&:after {
transform: rotate(-230deg);
right: 22px;
top: 13px;
height: 18px;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment