What we're listening to in the studio.
Home
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.
Tweets from the Studio
2012 British Gas Swimming Championships
Digital Creative Director - Manchester
PHP Developer - Manchester
sk:n E-Commerce
Skylab Get Social
Skylab Win Big Chip!
Skylab Makes Big Splash
Swimfit Web App
The new UNOFFICIAL interactive and open social network site for all things Media City.
Skylab Support the Northern Lights Programme
A big thank you to everyone who attended Manchester’s first Social Media Day
Join us in Manchester to celebrate Mashable’s first global Social Media Day
This Week in Twitter
British Swimming
Philip Lawrence Awards
Four Square Fever
Simply Be Blog
InjuryLawyers4U Website
Ruth Badger, Branding & Website
Man Utd Hospitality Sales Website
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 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
The Prodigy
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