This blog has moved here: woorkup.com
Saturday, January 26, 2008

Toggle effect using Scriptaculous

Another post dedicated to Scriptaculous and to a nice way to implement Toggle effect.

This tutorial explains how to implement a simple Toggle effect using Scriptaculous framework. I prepared a simple tutorial you can download to see it in action:


Download this tutorial

To use scriptaculous effect on your pages you have to add this lines of code in the <head> tag:

<script language="javascript" src="scriptaculous/prototype.js"></script>
<script language="javascript" src="scriptaculous/scriptaculous.js"></script>

Then, you can apply Scriptaculous Toggle effect using this simple code, for example calling this function inside "onClick" attribute:

Effect.toggle('ID','type-of-effect'); return false

...where "ID" is the element you want to apply the toggle effect and "type-of-effect" is a toggle "sub-effect" (blind, appear, slide). I chose as toggle sub-effect "blink":

<h1 onclick="Effect.toggle('about-me','blind'); return false">About me</h1>
<div id="about-me">...some content...</div>


In this way you can apply this effect to every element using HTML "id" attribute.

Download this tutorial

blog comments powered by Disqus
Lara said...

Nice effect!

mickbw said...

I am very lazy and don't always have the frameworks loaded.

Could you include a link to a sample page on your entries? I know you do this most of the time anyway.

Bobby said...

I noticed is that I couldn't get the effect to return false with an onmousedown event. How come?

REENKU said...

How can I set the panel property to closed by default? currently its open by default.

Nice effect btw.

waiting for your reply.
Regards,
Rakesh

RupertGee said...

Just change the enclosing div to < div style="display: none;"> and the panel will be hidden by default.

Louise said...

Thanks for posting the easiest way to toggle using scriptaculous effects already built in. Many people out there are trying to reinvent the wheel, writing extra scripts to do this.

Anonymous said...

Is there any standalone JS script that could do this one? I don't need any JS framework because this is the only effect I want.

  • Twitter Follow woork on Twitter
  • RSS Feed Subscribe to stay up to date
  • Podcast Coming soon...
  • 0 delicious lovers save
Support this blog with a micro subscription
If you like this blog you can contribute with a micro subscription via PayPal.
Share your links. Do you want to suggest any interesting link about web design or tech news? Submit your link.
Submit a News
Web Templates
Stock Vectors
THE CSS AWARDS