A jQuery plugin for floating form labels.
Based on a UI concept by Matt D. Smith.
Add jquery.FloatLabel.css to your websites stylesheets and jquery.FloatLabel.js to your scripts.
- Add jquery.FloatLabel.js to your scripts. Example -
<scriptsrc="scripts/jquery.js"></script><scriptsrc="scripts/jquery.FloatLabel.js"></script><scriptsrc="scripts/main.js"></script>- Add jquery.FloatLabel.css to your stylesheets. Example -
<linkrel="stylesheet" href="styles/normalize.css"><linkrel="stylesheet" href="styles/jquery.FloatLabel.css"><linkrel="stylesheet" href="styles/main.css">- Wrap the fields you wish to effect with your chosen class. Example -
<divclass="js-float-label-wrapper"><labelfor="name">Name</label><inputid="name" type="text"></div>- Initialise FloatLabel.js, passing the plugin your input/label wrapper class. Example -
$('.js-float-label-wrapper').FloatLabel();As FloatLabel.js works by using CSS classes, the animations can be tweeked within jquery.FloatLabel.css.
If the default classes conflict with the rest of your CSS for whatever reason, you can change them by passing in paramaters when you initialise the plugin. Don't forget to update jquery.FloatLabel.css with your new class names if you need to make a change.
$('.js-float-label-wrapper').FloatLabel({populatedClass : 'custom-populated-class',focusedClass : 'custom-focused-class'});