Created
September 15, 2011 22:42
-
-
Save craigmdennis/1220695 to your computer and use it in GitHub Desktop.
Slide labels away from input on focus
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
// Requires jQuery easing | |
function moveLabels() { | |
// Get the original position values | |
var pos = $('#contact label').css('left').replace('px', ''); | |
$('input[type=text],textarea').focusin(function () { | |
var label = $(this).prev('label'); | |
label.stop(true, false).animate({ | |
'left': -label.width() - pos | |
}, 200); | |
}); | |
// If the input is empty then animate it back in | |
$('input[type=text],textarea').focusout(function () { | |
if ($(this).attr('value') === '') { | |
var label = $(this).prev('label'); | |
label.stop(true, false).animate({ | |
'left': pos | |
}, 200); | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
TODO