Skip to content

Instantly share code, notes, and snippets.

@CodeMyUI
Created August 15, 2016 05:33
Show Gist options
  • Save CodeMyUI/07e942b3342abe77f8621cb485a28736 to your computer and use it in GitHub Desktop.
Save CodeMyUI/07e942b3342abe77f8621cb485a28736 to your computer and use it in GitHub Desktop.
Nearly CSS3 Animated Search Input
<!-- Design inspired by: https://dribbble.com/shots/1992789 -->
<form>
<input type="text" />
<div class="after"></div>
<input type="submit" />
</form>
<h4>&nbsp;</h4>
<p>Click search, Enter to submit</p>

Nearly CSS3 Animated Search Input

CSS3 animated search in input field. Inspired by a dribbble shot by sandeep virk, you can check out the original animation at: https://dribbble.com/shots/1992789

Although :focus animation was achievable entirely in CSS, JS was required for blur and submission animations.

A Pen by Wayne Dunkley on CodePen.

License.

var s = $('input'),
f = $('form'),
a = $('.after'),
m = $('h4');
s.focus(function(){
if( f.hasClass('open') ) return;
f.addClass('in');
setTimeout(function(){
f.addClass('open');
f.removeClass('in');
}, 1300);
});
a.on('click', function(e){
e.preventDefault();
if( !f.hasClass('open') ) return;
s.val('');
f.addClass('close');
f.removeClass('open');
setTimeout(function(){
f.removeClass('close');
}, 1300);
})
f.submit(function(e){
e.preventDefault();
m.html('Thanks, high five!').addClass('show');
f.addClass('explode');
setTimeout(function(){
s.val('');
f.removeClass('explode');
m.removeClass('show');
}, 3000);
})
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
html {
background-color: #E62878;
font-family: "Lucida Grande","Lucida Sans Unicode", Tahoma, Sans-Serif;
}
p {
text-align: center;
color: #fff;
font-size: 14px;
}
h4 {
color: #fff;
text-align: center;
letter-spacing: 0.5px;
transform: scale(0);
transition: all 0.3s;
position: relative;
top: -25px;
margin: 0;
font-weight: normal;
}
h4.show {
animation: alert 0.18s ease-in-out;
animation-fill-mode: forwards;
}
@keyframes alert {
0%{
transform: scale(0);
}
80% {
transform: scale(1.2);
}
100% {
transform: scale(1);
}
}
form {
transition: all 0.15s;
}
form.explode {
transform: scale(1.4);
opacity: 0;
}
html {
padding-top: 100px;
}
form {
width: 36px;
height: 36px;
margin: 0 auto;
display: block;
box-sizing: border-box;
position: relative;
}
input[type="submit"]{
display: none !important;
}
input {
width: 100%;
}
input {
background: none;
border: 3px solid #fff;
border-radius: 26px;
box-sizing: border-box;
padding: 5px 15px 7px;
font-size: 14px;
color: #fff;
z-index: 2;
position: relative;
}
input:focus {
outline: none;
}
.after {
width: 36px;
height: 36px;
position: absolute;
top: 1px;
right: 0;
z-index: 1;
}
form.open .after {
cursor: pointer;
}
.after:before,
.after:after {
content: '';
width: 13px;
height: 3px;
background-color: #fff;
border-radius: 3px;
position: absolute;
transform-origin: 100% 100%;
}
.after:after{
bottom: -3px;
right: -3px;
transform: rotate(45deg);
}
.after:before {
top: -3px;
right: -3px;
transform: rotate(-45deg);
opacity: 0;
}
form,
form .after,
form .after:before,
form .after:after {
animation-duration: 1.1s;
animation-fill-mode: forwards;
}
form.in {
animation-name: expand;
}
form.in .after:before {
animation-name: beforemagic;
}
form.in .after:after {
animation-name: aftermagic;
}
form.close,
form.close .after,
form.close .after:before,
form.close .after:after {
animation-direction: reverse;
}
form.close {
animation-name: expand;
}
form.close .after:before {
animation-name: beforemagic;
}
form.close .after:after {
animation-name: aftermagic;
}
/* Hold final focused state
****************************/
form.open {
width: 250px;
color: #fff;
}
form.open .after {
z-index: 3;
}
form.open .after:before {
width: 20px;
top: 9px;
right: 13px;
opacity: 1;
}
form.open .after:after {
width: 20px;
bottom: 10px;
right: 15px;
}
@keyframes aftermagic {
0% {}
10% {
width: 24px;
bottom: -10px;
right: -10px;
}
15%{
opacity: 1;
}
35% {
width: 13px;
bottom: -3px;
right: -3px;
opacity: 0;
}
25% {
opacity: 0;
}
64% {
opacity: 0;
}
65% {
opacity: 1;
width: 13px;
bottom: -2px;
right: -3px;
}
75% {
width: 30px;
bottom: 4px;
right: 10px;
}
90% {
width: 20px;
bottom: 10px;
right: 15px;
}
100% {
width: 20px;
bottom: 10px;
right: 15px;
}
}
@keyframes beforemagic {
0% {}
50% {
opacity: 0;
}
55% {
opacity: 1;
width: 13px;
top: -4px;
right: -3px;
}
65% {
width: 30px;
top: 6px;
right: 10px;
}
80% {
width: 20px;
top: 9px;
right: 13px;
}
100% {
width: 20px;
top: 9px;
right: 13px;
opacity: 1;
}
}
@keyframes expand {
0% {
color: transparent;
}
20% {
width: 36px;
}
45% {
width: 250px;
}
99% {
color: transparent;
}
100% {
width: 250px;
color: #fff;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment