Fork me on GitHub

In-Field Labels jQuery Plugin

Samples

Comment Form





Login Form



Use

HTML:

<p>
  <label for="field_id">Label Text</label><br />
  <input type="text" name="field_id" value=""
  id="field_id">
</p>

CSS:
More CSS is needed to position the label nicely over the input or text area element, but since it all depends on how you have styled those elements, only the bare-bones are listed here. Keep in mind any block element can surround the label and input field. <p> is used as an example.

form p { position: relative }
label.in-field {
  position: absolute;
  top: 0; left: 0;
  cursor: text;
  pointer-events: none; }

Javascript:

$(document).ready(function(){
  $("label").inFieldLabels();
});

Options

Five options can be passed along with the method or set ahead of time for all inFieldLabel controls.

To set them ahead of time, use the following syntax:

$.inFieldLabels.defaultOptions.optionName = "";

To pass them at call time, use the following syntax:

$("label").inFieldLabels({ optionName: value });

fadeOpacity: Value between 0.1 and 1.0.
When a field is focussed, its label is animated to this opacity. Defaults to 0.5

fadeDuration: Time in milliseconds
When an animation occurs, it uses this setting to determine duration. Defaults to 300

labelClass: String (CSS class to be applied to the label)
When the label becomes in-field, this class is applied to the label. This allows fallback styling for label that will not be in-field, for various reasons (inelligible, JavaScript is disabled, an error occured…). Defaults to 'in-field'

disableAutocomplete: Boolean
If true, disable browser auto-complete: the matching field gets autocomplete=off, which prevents some overlay errors when the field is still focused. Defaults to true

emptyWatch: Boolean
If true, keep watching the field as the user types. This allows the plugin to bring back the label as soon as it is empty, which prevents some overlay errors when the field is still focused. Defaults to true

Changelog

Version 0.2.1

Version 0.2, by Adrien Lavoillotte (streetpc)

Version 0.1.2

Version 0.1.1

Version 0.1

To Do

Download