top | item 4154258

CSS Animated Slide Toggle

78 points| tzm | 13 years ago |jsfiddle.net | reply

25 comments

order
[+] jmyc|13 years ago|reply
Just a suggestion: I was annoyed when I first tried to drag the slider. I figured out you have to click it instead, but some users may just quit first.
[+] PStamatiou|13 years ago|reply
We used to have two toggles for delivery settings (photo prints/email on/off-- coded as checkboxes) on Picplum and we quickly learned that people tried to drag them as well. So we reverted back to plain checkboxes. Sometimes just because you can do something (and it's pretty) doesn't mean it's usable.
[+] pazimzadeh|13 years ago|reply
I agree. If you're going for skeuomorphism you should take it all the way in terms of manipulating 3D elements.
[+] fady|13 years ago|reply
yeah, i did the same thing. maybe have both options available, or even when someone visits the site on a mobile device then the click n drag feature is enabled.
[+] douglascalhoun|13 years ago|reply
You can drag it, you just can't end the drag motion outside of the dongle area. Took me a few tries to figure that out myself.
[+] alexobenauer|13 years ago|reply
Very cool... in Webkit browsers. It's a shame few (if any) other browsers allow you to customize a checkbox this way.

Nonetheless, nice work on theming a native checkbox so well. I'd love to use it if it were cross-browser compatible.

[+] milesokeefe|13 years ago|reply
I wish joshnh would have included a note about webkit or lack of FF support. I toggled it for 30 seconds or so before opening the source, noticing it was webkit, and switching to Chrome.
[+] DArcMattr|13 years ago|reply
At a first glance, many of the -webkit-* rules in that project's CSS are implemented in other browsers, such as current versions of Opera and Firefox.

It looks like it's relying on the webkit-only "-webkit-appearance" property, as you can see here: http://jsfiddle.net/DArcMattr/uhwQp/1/show/

edit: added an attempt at making it cross-browser

[+] yaix|13 years ago|reply
Looks nice.

But I think the [x] or [ ] of a normal checkbox are more intuitive than two different colors that may have different meanings in other cultures/countries (and I am not even starting about color blindness).

[+] peeters|13 years ago|reply
I agree. I think it would go a long way to have the visible side display a red X or a green checkmark, rather than an ambiguous background.
[+] jacobr|13 years ago|reply
For CSS demos, I suggest using http://dabblet.com which will automatically add vendor-prefixes. In this case it might not have helped due to the appearance property (which was dropped from the CSS spec [1]), but often only webkit prefixes are used even if properties are supported in other browsers.

1: http://wiki.csswg.org/spec/css4-ui#dropped-css3-features

[+] martinaglv|13 years ago|reply
This won't actually work in any other engine except for webkit, even if you vendor-prefix the rules. This is because he is using an :after pseudo element on a checkbox, which shouldn't work and is technically a bug in webkit (according to the specifications, you cannot use :before/:after on replaced elements).
[+] mnicole|13 years ago|reply
I get a little tired of seeing people override their web form elements this way because they should only be used for gestural interfaces, and even then it can be annoying. Trying to translate it to web just causes confusion for the user -- they don't know whether to click on it (in which case it is too wide and bulky for many circumstances) or slide it (which is unnatural for the web outside of range sliders).
[+] groue|13 years ago|reply
What about adding the ability to drag the slider, so that the widget acts as it should act, that is to say as other sliding toggles? It would then be perfect! Rationale : that's again the problem of half-baked UI elements, which confuse their end-users, while the developpers feel satisfied and enjoy long drinks.
[+] sprobertson|13 years ago|reply
Thought it wasn't so cool until I checked it out to see that this entire thing is a single <input>, not even an image in sight. Great job. It'd be cool to see as a light-switch that did something with page contrast.
[+] danielschwartz|13 years ago|reply
You'd probably have a better framerate if you used translate or translate3d instead of a simple transition. Framerate is fine in Chrome but isn't fantastic on iPhone/iPad
[+] enoughalready|13 years ago|reply
On mobile devices, there is about a 1 to 1.5 second delay before the animation begins. touchstart and js might be a better solution...
[+] alexchamberlain|13 years ago|reply
The best bit about this is that the HTML markup has not been changed for the visual effects. Well Done!
[+] dr42|13 years ago|reply
It's really hard to use on the iPad, it doesn't behave how one might expect, click it makes the window zoom, clicking a second time slides the toggle. Sliding the toggle does nothing.
[+] gcb|13 years ago|reply
looks awful as hell in opera.

somehow it makes the browser render the checkmark behind the checkbox, you can barely see the end of the mark.