What we're listening to in the studio.
Home
LCD Soundsystem
View more at our Last FM page
30 July 2009
We recently found ourselves in need of an iPhone-style slider control for a web application we’re currently building. After a quick peruse of the web, it seemed nobody had already tackled this problem so we set out to solve it ourselves.
Here is a list of features we wanted it to have:
![]()
The technical specification breaks down as follows:
Here’s an example of how the code works. As you’ll see, we’ve made it nice and easy!
<script type="text/javascript">
Element.observe(window, 'load', function(e)
{
var mySlida = new Effect.Slida('mySlidaForm', {
onLabel: 'Active',
offLabel: 'Inactive'
});
});
</script>
<form id="mySlidaForm" action="/change-state">
<fieldset>
<input type="checkbox" name="state" checked="checked"/><label>active</label>
<button type="submit">Submit</button>
</fieldset>
</form>
The Slida effect hijacks the form that is passed to it and replaces it with the HTML for the Slida element. When the user changes the slida’s state, an AJAX call is made to the url defined by the form’s action. The parameter name is the same name as the checkbox element in the original form.
In the example above the AJAX call would be to:
/change-state?state=off
or
/change-state?state=on
This means that the same post is made to the server for an AJAX call or a form submission.
1) Ensure you have the latest copies of Prototype and Scriptaculous - include them on your page:
<script type="text/javascript" src="prototype.js"></script>
<script type="text/javascript" src="scriptaculous.js?load=effects,slider"></script>
2) Download the Slida package and put it in your html directory. Include the javascript and css file.
<script type="text/javascript" src="slida/slida.js"></script>
<link rel="stylesheet" type="text/css" media="screen" href="slida/slida.css" />
3) Create a form on your page
<div id="wrapper" style="width: 250px">
<form id="mySlidaForm" action="/change-state">
<fieldset>
<input type="checkbox" name="state" checked="checked"/><label>active</label>
<button type="submit">Submit</button>
</fieldset>
</form>
</div>
The slida will fill the width of its parent container.
4) Create a new Slida effect, passing the ID of the form element and supplying the label text for the on/off states.
<script type="text/javascript">
Element.observe(window, 'load', function(e)
{
var mySlida = new Effect.Slida('mySlidaForm', {
onLabel: 'Active',
offLabel: 'Inactive'
});
});
</script>
setValue(state) - sets the state of the slida
e.g.
mySlida.setState(true)
toggleValue() - toggles the value of the slida
e.g.
mySlida.toggleValue()
The latest feeds from the studio powered by Yahoo Pipes.
We're so close to "the big day" we just can't help but wish everyone a Merry Christmas!
@steve_worsley Great night had by all!
RT @steve_worsley: Cracking @studioskylab party last night! Managed not to suck too much at bowling for once!
@jaikdean Glad you enjoyed :-)
RT @jaikdean: Fun evening out with the @studioskylab crew. Always nice bumping into those rogues @rachael_burns and @James_Galley too.
RT @cassons_sage: Thanks for all the wonderful feedback we've received ref our Xmas video. http://t.co/y21CEoeA Thanks again @studioskylab!
@cassons_acc Our pleasure as always!
RT @cassons_acc: Huge thanks to @nigelcollier & @studioskylab for our Christmas greetings! http://t.co/y21CEoeA Merry Xmas!!
My Top 3 #lastfm Artists: John Williams (18), The Future Sound Of London (11) & deadmau5 (10) #mm http://t.co/NDO397rO
@roberthempsall Thanks for the retweet Robert
@liz_e Thank you so much!
My Top 3 #lastfm Artists: Thomas Newman (15), Caravan Palace (15) & Sigur Rós (11) #mm http://t.co/NDO397rO
@liz_e Hi Liz, must be based at our studio in Manchester, hope this helps you
We're still looking for a great freelance web designer for a few months, starting ASAP. Email [email protected] Pls RT
My Top 3 #lastfm Artists: The Qemists (2), Air (1) & Iggy Pop (1) #mm http://t.co/NDO397rO
@emilyob_20 Hi Emily, please send your cv across to [email protected] and i'll take a look.
@cassons_acc It's only 51 sleeps, 10 hours and 16 minutes until Xmas!
RT @r3vok: Nice concept and illustrations - UNICEF + Threadless - Buy Good Shirts, do good. http://t.co/8aenzJuX
Still Hiring coders #PHP5 #MySQL #Javascript #systemadmin #AWS #Symfony #CodeIgniter #Zend http://t.co/OasIWlWv Pls RT
sk:n E-Commerce
Skylab Makes Big Splash
Swimfit Web App
The new UNOFFICIAL interactive and open social network site for all things Media City.
British Swimming
Philip Lawrence Awards
Hosted forms - looks very nice!
Shows Twitter client usage for all accounts tracked by @twitstat.
One to keep an eye on. Standalone reusable PHP classes from Symfony.
The Prodigy
The Future Sound of London
Booty Luv
Massive Attack
808 State
Layo & Bushwacka!
Shakedown
Lay claim to the sites you build.
M.I.A.
M.I.A.
Plump DJs
Plump DJs
The Upsetters
Goldie
Orbital
The Cinematic Orchestra
Petter & The Pix
Plump DJs
Beck
The Black Ghosts
Sydney Miller & Moraes Moreira
Various Artists
Comments
omg
Wed Sep 16, 2009 at 5.06am
This is great. However, what about if we want to have multiple slida on the same page? How would you add more?
Post a Comment