Skip to content

Instantly share code, notes, and snippets.

@tammyhart
Created October 16, 2013 15:39
Show Gist options
  • Save tammyhart/7009831 to your computer and use it in GitHub Desktop.
Save tammyhart/7009831 to your computer and use it in GitHub Desktop.
Fade out symmantic labels positioned over fields
// labels
function inlineLabels() {
var $this = $( this ),
id = $this.attr( 'id' ),
$label = $( 'label[for=' + id + ']' );
if ( $this.val() != '' )
$label.css( 'opacity', 0 );
$this.on( 'focus', function() {
if( $this.val() == '' )
$label.animate( { opacity: 0.5 }, 250 );
} );
$this.on( 'keyup', function() {
$label.css( 'opacity', 0 );
} );
$this.on( 'blur', function() {
if( $this.val() == '' )
$label.animate( { opacity: 1 }, 250 );
} );
}
$( 'input, textarea' ).each( inlineLabels );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment