Last active
December 25, 2015 10:19
-
-
Save divins/6960679 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="input"> | |
<input id="foo" placeholder="Foo"> | |
<label for="foo">Foo</label> | |
</div> | |
<div class="input"> | |
<input id="bar" placeholder="Bar"> | |
<label for="bar">Bar</label> | |
</div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script type="text/javascript">$(function() { | |
$('input').keyup(function(){ | |
label = $('label[for="'+this.id+'"]') | |
if( !this.value ) { | |
label.removeClass('filled') | |
} | |
else{ | |
label.addClass('filled') | |
} | |
}) | |
});</script> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.input { | |
position: relative; | |
} | |
.input label { | |
opacity: 0; | |
position: absolute; | |
top: 0px; | |
left: 0px; | |
font-size: 11px; | |
} | |
.input label.filled { | |
opacity: 1; | |
-webkit-transition-property: opacity; | |
-moz-transition-property: opacity; | |
-o-transition-property: opacity; | |
transition-property: opacity; | |
-webkit-transition-duration: 0.3s; | |
-moz-transition-duration: 0.3s; | |
-o-transition-duration: 0.3s; | |
transition-duration: 0.3s; | |
top: -3px; | |
-webkit-transition-property: top; | |
-moz-transition-property: top; | |
-o-transition-property: top; | |
transition-property: top; | |
} | |
.input input { | |
border: 0; | |
border-bottom: 1px solid #bbbbbb; | |
outline: none; | |
margin: 10px 0px; | |
font-size: 15px; | |
} | |
.input input:focus + label { | |
color: blue; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.input | |
position: relative | |
label | |
opacity: 0 | |
position: absolute | |
top: 0px | |
left: 0px | |
font-size: 11px | |
&.filled | |
opacity: 1 | |
+transition-property(opacity) | |
+transition-duration(0.3s) | |
top: -3px | |
+transition-property(top) | |
input | |
border: 0 | |
bottom: 1px solid #bbb | |
outline: none | |
margin: 10px 0px | |
font-size: 15px | |
&:focus + label | |
color: blue |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment