The Yellow Llama | Web Design South Africa

AJAX-ify your site in 5 minutes

I’m discovering the wonders of AJAX. Its an awesome means of making smooth transitions on your website. When pages flicker and jump too quickly to the next link, users can be left unaware that anythings actually happened. With a nice (and easy to do) transition, your page can slide down when loaded and slide up when you’re done.

I’m unfortunately not skilled enough to write my own AJAX functions, but thanks to the likes of Scriptaculous and Prototype, and guru’s like Michael Heilemann, I don’t need to be. :)

I recently combined some techniques on 24 Ways to make some nice transitions on a site I’m working on. Heres how it all works…

The code

You’ll need this bit of code saved as combo.js

Effect.OpenUp = function(element) {
element = $(element);
new Effect.BlindDown(element, arguments[1] || {});
}
Effect.CloseDown = function(element) {
element = $(element);
new Effect.BlindUp(element, arguments[1] || {});
}

Effect.Combo = function(element) {
element = $(element);
if(element.style.display == 'none') {
new Effect.OpenUp(element, arguments[1] || {});
}else {
new Effect.CloseDown(element, arguments[1] || {});
} }

Then you can download prototype.js and effects.js which you’ll find in the Scriptaculous Library

Link to all 3 of these documents in the head of your site.

Sorted. Thats the hard part.

The div

Your site should have a wrapping div… a container around all your code. If not, add one and set it to display:none; like this:

div id="wrap" style="display: none"

Note: The div needs to have an id, not a class.

The trigger

javascript:Effect.Combo('wrap');

Now under normal circumstances, your trigger would be a link somewhere that would slide open/close your hidden div, but in this case, we’re applying the effect to the entire site. So we’re going to use the onload trigger on the body like so:

body onload="javascript:Effect.Combo('wrap');"

Now, when the body loads, it’ll run that effect and presto, your body slides open all nice and smooth.

Thats that.. :) Let me know how it works for you

Leave a Reply



Blog News & Articles

What’s being loaded into this plane?

Its a hard disk in 1956.... HDD with 5MB storage in 1956. In September 1956 IBM launched the 305 RAMAC, the first computer with a hard disk drive (HDD). The HDD weighed over a ton and stored 5MB of data. Start appreciating your 1 GB memory ...

The WordPress Guru is launched

For the last 4 or 5 years that I've been using WordPress, I've managed to pick up a good few tips and tricks. 90% of my clients are sites who require content management systems, not blogs. And thus I've been able to create highly tweaked ...

A blind man wanders into an all-girls biker bar by mistake…

A blind man wanders into an all-girls biker bar by mistake. He finds his way to a bar stool and orders some coffee. After sitting there for awhile, he yells to the waiter, 'Hey, you want to hear a blonde joke? The bar immediately falls absolutely silent. ...

Looking for trouble…

Best part is when the dog looks up at the cat like... WTF are you doing...

26 Reasons why dogs bite people

...

Examples of Kulula attendants’ sense of humor

Kulula is an Airline with head office situated in Johannesburg. Kulula airline attendants make an effort to make the in-flight "safety lecture" and announcements a bit more entertaining. Here are some Real examples that have been heard or reported: On a Kulula flight, (there is no assigned seating, ...