Sliding Labels Official Plugin Release [ver. 3.2]
Version: 3.2 – Added a “className” option so you don’t have to use “.slider” as the wrapper
Version 3.1: Changed “children” to “find” so it will work with a UL. Thanks to Oro for the feedback
Version 3 of Sliding Labels brought some big changes, the largest being that I finally converted it into a working jQuery plugin.
Maybe it was the 200 e-mails requesting an official plugin, maybe it was my curiosity. Whatever it was, I heard everyone and I wanted to let you know that I’m listening to all the feature requests and bug reports; and I really do appreciate them.
Additions to version 3
Plugin status: Obviously creating an official plugin was the biggest change
Position: relative: It seemed like a lot of the questions I was getting had to do with adding position:relative to the .slider element in the CSS, so I just moved that into the script.
Animation speed: I added an option to easily control the animation speed. It can take strings like “fast” and “slow” or any numeric value.
Axis option: I got a lot of requests to add in some functionality to have the label slide up rather than only to the left. I added this in with an “axis” variable which can take either “x” or “y” for sliding direction
Subtractions to version 3
Label Color: Originally I had this in the script so it looked nicer inline to the field, but I got to thinking that this really should be defined in the CSS, and it’s just color; so I took it out.
Using the plugin
Just like the previous version, you need an element wrapping the <label> and <input> elements. I use a <div> in the demo, but you can use whatever you’d like. The only requirement is that it have the class name “slider”. I can change that if anyone finds it to be annoying, but let me know and I’ll update the script
HTML
<div class="form-slider">
<label for="user">User name</label>
<input type="text" id="user" name="user">
</div>
JavaScript
$(function(){
$('#contactform').slidinglabels({
/* these are all optional */
className : 'form-slider', // the class you're wrapping the label & input with -> default = slider
topPosition : '5px', // how far down you want each label to start
leftPosition : '5px', // how far left you want each label to start
axis : 'x', // can take 'x' or 'y' for slide direction
speed : 'fast' // can take 'fast', 'slow', or a numeric value
});
});
That’s all there is to it. Let me know what you think, any extra features you’d like and any bugs. I should be submitting this to jQuery.com in the next few days.
You can leave a response, or trackback from your own site.
« Books that made me a better designer | Our Curious Future with QR Codes »
Comments (50)
|
Trackbacks & Pingbacks (8)
-
[...] Please use version 3 of sliding labels with updated options and bug fixes at: http://www.csskarma.com/blog/sliding-labels-plugin/ [...]
-
links for 2010-04-30…
Sliding Labels Official Plugin Release « CSSKarma (tags: webdev javascript jquery plugin forms label)…
-
[...] Le blog cssKarma vous propose le plugin Sliding Labels. [...]
-
[...] 4. Sliding Labels Plugins [...]
-
[...] Sliding Labels Official Plugin Release « CSSKarma Ok, this one would come in handy as well. [...]
-
[...] Sliding Labels Official Plugin Release « CSSKarma (tags: form jquery plugin) [...]
-
[...] window.location = "http://www.csskarma.com/blog/sliding-labels-plugin/" Please use version 3 of sliding labels with updated options and bug fixes at: http://www.csskarma.com/blog/sliding-labels-plugin/ [...]
-
[...] Sliding Labels Official Plugin Release « CSSKarma – Share and Enjoy: [...]
Leave a Reply



Hey Tim, this is awesome! Can’t wait to implement this wherever I can, it’s such a neat feature and one that has had people go crazy over it in a good way
You certainly hit a winner with this one!
Thanks Laneth!
Great script, thanks for your effort! having to use the class name “slider” may cause conflicts for people who are using a carousel script or something like that, but otherwise excellent!
Thanks Aonghus, I kinda thought taht might be the case, I can update the script so class name is an option.
Another vote for making the magic class name a configurable option, but is it actually needed at all?
Why can’t the plugin operate on a list of jQuery elements – e.g. $(‘.MySlidingLabelClassName’).slidinglabels() like most other plugins – instead of on the form element itself?
Not only would this make the plugin more flexible (leaving the class up to the developer, and also permitting the use of multiple classes) but it would also open up the potential to use chaining to apply other handlers to the same selected form elements, which is something you’re (traditionally) unlikely to want to do with the form element…
Tim, interesting solution…like the alternate solution to a common problem. Wonder if there is a way to build in form validation to this plugin. Maybe the label changes color, or an icon is presented once something is typed and verified.
Never really thought about validation but now that you mention it, I bet the regular validation plugin would have trouble with this since it produces another label. Worth testing
bug: line 93 — .blur if axis = y then ‘top’: defaults.leftPosition… should be topPosition
Fixed. Nice catch, thanks
Hey!
Great job with this plugin. I’m already using it.
Sometimes the web browser fills form automatically, and with Google Chrome (didn’t try with another one yet), the label slide into the input even if there is a value. Can you think of a solution ?
That’s weird, I thought I fixed that. I’ll take another look. Thanks for letting me know!
This plugin is nice. I had some trouble getting it to work with my form. It turns out I had wrapped all my sliders inside another div that was in the form, so nothing was happening. I didn’t know the elements with class slider needed to be direct descendants of the element used to initialize. I would suggest modifying it to find all children with class slider, so I can nest as needed. This might be more of a preference than an actual need for the plugin, but thought I would mention.
——————–
FF 3.6. Mac OS 10.4
@tim too Have you found a solution for this? I haven’t been able to figure anything out so that I can position my form and style it the way I want it to be without killing the sliding technique. Let me know if you find something! Otherwise, this is a fantastic plugin
Keep posting stuff like this i really like it
I can’t get this to work if I change the form’s id to anything other than “contactform”. Any suggestions?
I guess I need sleep. Turns out I was actually making changes to the code within the
section of the demo.The fix to your div problem, or for that matter, any other issue involving your slider div’s being nested inside another element (such as fieldset) is to simply include that tag when you specify the form ID. Example:
$(‘#formID fieldset’).slidinglabels()
This is the best jQuery-based plugin for field hinting that I’ve found, as for me it is absolutely crucial that the HTML is semantically (and syntactically) valid, and that the label is fully accessible and visible at all times.
However, for rare occasions where space is extremely tight and therefore there’s simply no space for the label to slide to either vertically or horizontally, it would be nice to be able to fade it out instead. This can of course already be achieved with other plugins but I would prefer to use a single plugin to cover both scenarios, so please consider adding fading as an alternative behaviour, with the % opacity for the field focus (but empty) state being configurable. (i.e. 100% opacity label –> field gains focus –> label fades to N% –> disappears instantly upon typing –> reappears if inputted text is deleted)
I think that would be a nice addition.
Do you know the name of the plugin that does the fadeOut? I know I’ve seen it and I’d like to credit the original developer if I add it to the plugin
If fading labels were actually original I would agree that you should credit but there are countless (well, at least 4) implementations of fading labels, so no credit needed IMHO, it’s your sliding implementation that’s actually original!
PS – here’s one example which features the two fade parameters that you would need to add (in addition to one to enable fading, unless you reworked an existing parameter): http://fuelyourcoding.com/scripts/infield/
perfect. That’s what I was looking for. Thanks Marcus
Great job man! I need to put this to use ASAP!
Great work! I did something similar on a wordpress theme of mine: http://cpackage.timgweb.com/contact/
The labels remain inside the input (well, technically not “inside”, they are just positioned to appear so), and disappear when you type. This eliminates any need for space outside the form. Might be a nice option to add to your plugin in the future.
Nice is there is any download link?
you can get the plugin code by clicking the “plugin” button at the top. Check out the demo for usage and whatnot
Hi, this plugin is awesome.
Yet having a blank on the left is not really nice when you discover the form.
So I’d like to open my contact form with the first label already on the left from his input (without clicking anywhere).
Does it possible ?
Sorry if my english is not perfect, I’m french ^^
Thanks a lot for your response.
If you’re using HTML 5 you can set an attribute of “autofocus” on that element and it should be slid out by default. You can read more on autofocus here: http://www.whatwg.org/specs/web-apps/current-work/multipage/association-of-controls-and-forms.html#autofocusing-a-form-control
Thanks for your quick answer. I tried many things, focus with jquery, html5, but the label doesn’t move far on the left. It stays to closed to the input.
Does it work in your script ?
Sorry, it works with : $(‘input’).focus(). I put my form in a modal window.
I had to modify some elements but independant from your sliding labels.
So great job I appreciate !
Nice script, but… I want the labels on the other site of the input (just as in the reply form of this page) is that possible also? When I run the script the labels always end up at the left side of the inputs
Any luck getting this to play nice with the Jquery UI Datepicker? On Chrome, the label slides left when the DatePicker pops up but once you select a date it slides back into the field as if it was empty.
Probably not the most elegant solution but it’s all I have for now.
$(".datepicker").datepicker({onClose: function() {$('#myform').slidinglabels();}});
Small addition:
Instead of using $.children to find the children with the class .slider, use $.find .
Then it’s possible to use e.g. a list to style the form, because $.children only searches the immediate children (one level in the DOM), and .find searches further down the DOM-tree.
Thanks, I added this into version 3.1
Hey guys, I should have a new version of the plugin out soon, just been a bit busy! Thanks for all the comments.
Found a new issue – dragging text into the field doesn’t work, as it doesn’t give the field focus. It’s arguably a rare edge case but it’s a perfectly valid thing to do, especially with TEXTAREAs…
One other suggestion for you, would be to take the label text and apply it to the title attribute of the field it is for, that way, if the label is a fade out, you will still know what the field is for.
Tim;
Hi, this is really nice code, but i have some trouble to fix it, i noticed that if i put value name, it won’t work right! for sample
country <input name="country" type="text" id="country4" value="” class=”required” />
There is other way can done with value name!
Alidad
This is a really cool form! Thanks so much for sharing
I have a problem tho, my div class is set to “form-slider” and i’ve also made sure that: the className : ‘form-slider’ (is like this in the javascript file).
But its not working..! Does anyone know what to do?
Please bear with me – i’m new to jQuery and Javascript.
Thanks
Do you have a live demo anywhere?
Yea you can see it here… http://bit.ly/ctg0bP
Thanks!!
The labels are not inside the actually input fields.. Hope you know what to do
Hi Shoh,
This is a jQuery plugin, so you’ll need to get jQuery for it to work. You can find it at jquery.com
Oh yea… okay, so I downloaded the jquery library and called it jquery.js and added the file to my directory. I also made script src from my index.html (to the jquery.js) but its still not working. Do I need to add to my function.js file also?
So sorry to be asking all these questions :S
Place your reference to jquery.js above formfunctions.js in the head and it should work. Just and ordering problem.
hi! just wanna know how can i style the form? which file should i need to use for styling the contact form? tnx!
I put some styles in the demo you can take a look at if you want. just click “style this form me”
Hi Tim, great work with this nice Plugin!
I just made a small addition, to configure the offset for the Sliders.
Maybe you want to ass this to the GIT:
1) Add a offset Parameter to the defaults:
speed : ‘fast’,
offset : 15
};
2) use this offset in the labels.each:
a) var labelmove = labelwidth + defaults.offset + “px”;
b) var adjust = width + defaults.offset + ‘px’;
regarda
Christoph
Hi,
very well performed, man.
I have a quick Q though.
How can I active the “action” attribute? I mean how can I make it work when I submit?
Is there any php, or whatever for it?
also I can’t style it the way I want.
Thanks again man
I’m not sure I follow. Do you have a live example anywhere?