What we're listening to in the studio.
Electronic Battle Weapon 10
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.
My Top 3 Weekly #lastfm artists: Arctic Monkeys (25), The Strokes (22) and Leftfield (21) #mm http://bit.ly/a4we45
@robhayward Hi Rob, could you please send a quick email with details to careers@studioskylab.com - the company Directors will pick that up.
@jkale Always interested in hearing from new talent. Please send details over to careers@studioskylab.com
Please send CVs and covering letters to careers@studioskylab.com
We are recruiting for Account Managers, Senior PHP Coders, Freelance Coders, Designers, Film Producers, Project Managers http://ow.ly/2A2f9
@PebbleArt Your welcome! We are currently recruiting for talent. Please spread the word http://ow.ly/2yswc :)
@andrewdisley Skylab need Acc Manager, Senior PHP Coder, Freelance Coders, Designers, Film Producers, Project Managers http://ow.ly/2yo3Y
@gablaxian Great, will look out for it :)
@northerndigital Could you please help out and RT the previous message to your lovely followers! :)
@northerndigital Skylab need Acc Manager, Senior PHP Coder, Freelance Coders, Designers, Film Producers, Project Managers http://ow.ly/2ynWO
@gablaxian Sounds great, please send your details to careers@studioskylab.com
@gablaxian Thanks for the RT, much appreciated!
Skylab are recruiting: Account Manager, Senior PHP Coder, Freelance Coders, Designers, Film Producers, Project Managers http://ow.ly/2ynli
My Top 3 Weekly #lastfm artists: The Black Ghosts (11), Boy 8-Bit (1) and French Fries (1) #mm http://bit.ly/a4we45
@davidlogan Can you call Lisa re. italy in the office
My Top 3 Weekly #lastfm artists: The Mars Volta (2), Burt Bacharach (2) and Björk (1) #mm http://bit.ly/a4we45
RT @nigelcollier: 2010 Roses Design Awards creates award for Best Pubic Building. Yes... 'Pubic'. Yuk! http://ow.ly/i/3jDa
My Top 3 Weekly #lastfm artists: The Aloof (10), Thom Yorke (9) and Siriusmo (2) #mm http://bit.ly/a4we45
@manairport We don't like to take all the credit! Am flying from @manairport on Sat so will test your fab service!
The new UNOFFICIAL interactive and open social network site for all things Media City.
Various Artists
The Prodigy
The Prodigy
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.
Incredible food at your desk - from 2.99 delivered! Love the branding.
Nice photography portfolio.
Nice little Google Maps app for planning walks in the Lakes.
Lay claim to the sites you build.
Twitter retweet trending.
An interesting read from the BBC on domain driven software design.
The full version (TweenMax) is larger, but includes bezier paths and filter tweens
stop motion tvs
Comments
omg
Wed Sep 16, 2009 at 6.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