Created
February 24, 2013 15:00
-
-
Save Beneboe/5024134 to your computer and use it in GitHub Desktop.
makes labels go inside an input tag
This file contains 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
<form action="/message"> | |
<p> | |
<label for="user_tel">Telephone:</label> | |
<input type="text" id="user_tel"><br /> | |
</p> | |
<p> | |
<label for="user_msg">Message:</label> | |
<textarea name="" id="user_msg" cols="30" rows="10"> | |
</textarea><br /> | |
</p> | |
<input type="submit" value="Absenden"> | |
</form> |
This file contains 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
$('label').addClass('labelinside'); | |
$('label').closest('p').find('input, textarea') | |
.on('focus', function() { | |
$(this).prev().animate({'opacity': '0.5'}, 100); | |
$(this).on('keydown', function() { | |
$(this).prev().hide(); | |
}); | |
}) | |
.on('blur', function() { | |
$(this).prev().animate({'opacity': '1'}, 100); | |
if($(this).val() === '') { | |
$(this).prev().show(); | |
} | |
}) |
This file contains 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
.labelinside { | |
position: absolute; | |
padding: <some padding>; | |
color: #000; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment