Sliding Labels v2 – Patch
Last week I wrote an article about sliding form labels that got quite a bit of attention. Many of the commenters brought up a couple good points/bug in the Sliding Label code that I wanted to address and provide a patch for:
- The sliding label was barfing out in Safari when auto-fill was active
- The default scripting didn’t work on textareas
I sat down yesterday and wrote a patch/new version of sliding labels which I think addresses these two problems.
The new jQuery
$(function(){
$('form#info .slider label').each(function(){
var labelColor = '#999';
var restingPosition = '5px';
// style the label with JS for progressive enhancement
$(this).css({
'color' : labelColor,
'position' : 'absolute',
'top' : '6px',
'left' : restingPosition,
'display' : 'inline',
'z-index' : '99'
});
var inputval = $(this).next().val();
// grab the label width, then add 5 pixels to it
var labelwidth = $(this).width();
var labelmove = labelwidth + 5 +'px';
// onload, check if a field is filled out, if so, move the label out of the way
if(inputval !== ''){
$(this).stop().animate({ 'left':'-'+labelmove }, 1);
}
// if the input is empty on focus move the label to the left
// if it's empty on blur, move it back
$('input, textarea').focus(function(){
var label = $(this).prev('label');
var width = $(label).width();
var adjust = width + 5 + 'px';
var value = $(this).val();
if(value == ''){
label.stop().animate({ 'left':'-'+adjust }, 'fast');
} else {
label.css({ 'left':'-'+adjust });
}
}).blur(function(){
var label = $(this).prev('label');
var value = $(this).val();
if(value == ''){
label.stop().animate({ 'left':restingPosition }, 'fast');
}
});
}); // End "each" statement
}); // End loaded jQueryTextarea HTML
The HTML for the textarea follows the same convention as the rest of the inputs, in only needing a wrapping element.
<div id="comment-wrap" class="slider">
<label for="comment">Comment</label>
<textarea cols="53" rows="10" id="comment"></textarea>
</div><!--/#comment-wrap-->There are no major changes to the plugin, just a few tweaks. If you find anymore bug, please let me know.
Both comments and pings are currently closed.
« Redirection Options | Penn UI Conference & HTML 5 »
« Older Comments | Newer Comments »
Comments (42)
Trackbacks & Pingbacks (74)
[...] Site: http://www.csskarma.com/blog/sliding-labels-v2/ [...]
[...] Sliding labels through jquery [...]
[...] Sliding Labels Am besten versteht man was das Plugin tut, wenn man sich die Demo anschaut. Eine normale HTML Form, deren Beschriftung auf die Seite geht, wenn man in ein Feld schreiben will. Fein! [...]
[...] 8. Раздвижные ярлыки [...]
[...] Sliding Labels [...]
[...] Sliding Labels [...]
[...] Josh McVeigh-Schultz shared Sliding Labels v2 – Patch « CSSKarma [...]
[...] Sliding Labels v2 Form label keeping the label inline, but sliding it off to the left rather than going away on click. [...]
[...] couple of different implementation approaches and figure out the best way to implement this feature.Sliding LabelsTim Wright came up with a jQuery technique that presents labels in input fields by default but then [...]
[...] Sliding LabelsTim Wright came up with a jQuery technique that presents labels in input fields by default but then slides them to the left (or up) rather than removing them on click. If JavaScript is turned off, the labels are displayed above the input fields. The small jQuery snippet works in all major browsers and can be used for input and textarea elements. [...]
[...] Sliding LabelsTim Wright came up with a jQuery technique that presents labels in input fields by default but then slides them to the left (or up) rather than removing them on click. If JavaScript is turned off, the labels are displayed above the input fields. The small jQuery snippet works in all major browsers and can be used for input and textarea elements. [...]
[...] Sliding LabelsTim Wright came up with a jQuery technique that presents labels in input fields by default but then slides them to the left (or up) rather than removing them on click. If JavaScript is turned off, the labels are displayed above the input fields. The small jQuery snippet works in all major browsers and can be used for input and textarea elements. [...]
[...] Sliding Labels Tim Wright came up with a jQuery technique that presents labels in input fields by default but then slides them to the left (or up) rather than removing them on click. If JavaScript is turned off, the labels are displayed above the input fields. The small jQuery snippet works in all major browsers and can be used for input and textarea elements. [...]
[...] Sliding LabelsTim Wright came up with a jQuery technique that presents labels in input fields by default but then slides them to the left (or up) rather than removing them on click. If JavaScript is turned off, the labels are displayed above the input fields. The small jQuery snippet works in all major browsers and can be used for input and textarea elements. [...]
[...] Sliding LabelsTim Wright came up with a jQuery technique that presents labels in input fields by default but then slides them to the left (or up) rather than removing them on click. If JavaScript is turned off, the labels are displayed above the input fields. The small jQuery snippet works in all major browsers and can be used for input and textarea elements. [...]
[...] that claims it improves the user experience, I’m hesitant to adopt.Such is the case with Sliding Labels.Sliding Labels is a jQuery plug-in that places form element labels inside of [...]
[...] ont nommé cela SlidingLabels et un démo est disponible directement [...]
[...] Sliding Labels Tim Wright came up with a jQuery technique that presents labels in input fields by default but then slides them to the left (or up) rather than removing them on click. If JavaScript is turned off, the labels are displayed above the input fields. The small jQuery snippet works in all major browsers and can be used for input and textarea elements. [...]
[...] 8. Sliding Labels [...]
[...] 8. Sliding Labels [...]
[...] Sliding LabelsTim Wright came up with a jQuery technique that presents labels in input fields by default but then slides them to the left (or up) rather than removing them on click. If JavaScript is turned off, the labels are displayed above the input fields. The small jQuery snippet works in all major browsers and can be used for input and textarea elements. [...]
[...] Sliding LabelsTim Wright came up with a jQuery technique that presents labels in input fields by default but then slides them to the left (or up) rather than removing them on click. If JavaScript is turned off, the labels are displayed above the input fields. The small jQuery snippet works in all major browsers and can be used for input and textarea elements. [...]
[...] Sliding LabelsTim Wright came up with a jQuery technique that presents labels in input fields by default but then slides them to the left (or up) rather than removing them on click. If JavaScript is turned off, the labels are displayed above the input fields. The small jQuery snippet works in all major browsers and can be used for input and textarea elements. [...]
[...] Sliding LabelsTim Wright came up with a jQuery technique that presents labels in input fields by default but then slides them to the left (or up) rather than removing them on click. If JavaScript is turned off, the labels are displayed above the input fields. The small jQuery snippet works in all major browsers and can be used for input and textarea elements. [...]
[...] approaches and figure out the best way to implement this feature. class="showcase"> Sliding Labels Tim Wright came up with a jQuery technique that presents labels in input fields by default but then [...]
[...] Sliding Labels Tim Wright came up with a jQuery technique that presents labels in input fields by default but then slides them to the left (or up) rather than removing them on click. If JavaScript is turned off, the labels are displayed above the input fields. The small jQuery snippet works in all major browsers and can be used for input and textarea elements. [...]
[...] Sliding Labels [...]
[...] Sliding Labels Tim Wright came up with a jQuery technique that presents labels in input fields by default but then slides them to the left (or up) rather than removing them on click. If JavaScript is turned off, the labels are displayed above the input fields. The small jQuery snippet works in all major browsers and can be used for input and textarea elements. [...]
[...] y puede ayudar a ahorrar espacio en los formularios mediante el uso de etiquetas para cada campo.Sliding LabelsTécnica jQuery para presentar las etiquetas de los campos de entrada del formulario mediante [...]
[...] Sliding Labels v2 Form label keeping the label inline, but sliding it off to the left rather than going away on click. [...]