My client wanted to make a transition between pages. I thought it would be difficult to do, but with help of Scriptaculous effects and Prototype's $$() function it turned out to be pretty simple.
The method I used is easy to use, unobtrusive and needs only one element which usually is already in the code – main div surrounding all page content.
Add Javascript libraries
- Download the linkToFade.js file
- Add Prototype, Scriptaculous and linkToFade files
<script type="text/javascript" src="scriptaculous/lib/prototype.js"></script>
<script type="text/javascript" src="scriptaculous/src/scriptaculous.js?load=effects"></script>
<script type="text/javascript" src="linkToFade.js"></script>
Write the (X)HTML
It's normal HTML one would use for the page. Just the link needs to have a class named „fade“
<div id='page'>
<!-- ... -->
<a href='standard_link' class='fade'>Link</a>
<!-- ... -->
</div>
Initiate linkToFade functions
Add following after the (X)HTML code given above:
<script type='text/javascript' language='javascript'>
Event.observe(window,'load',
function () {
// inititate the link to fade functions
initiateLinkToFade();
}
);
</script>
We've got the linkToFade functionality. To make the page also appear on load one has to add this just before initiating the link to fade:
// make the page appear on load
$('page').hide();
new Effect.Appear('page');
// inititate the link to fade functions
initiateLinkToFade();
That's it! Grab your linkToFade.js and share the news below:









Comments
what's your name? bmx
oh I didn't know we can do this… great! thanks! I'll try to do this on my blog,
which function is $$()?? i never read it in any of the books?
-Andy
You missed a file http://piotr.zalewa.info/…c/effects.js
you need to add that to the same directory as scriptaculous.js
When I call the scripts in your website (by pasting the links in your exemple), it's working. But when I call the scripts I've downloaded, it's not… well, what's wrong ?
@Anonymous and IE7
I may have to test it again, but to my knowledge it does work under IE7. It was used on http://bboyunderwear.com .
great!but not working in IE7
Hi Ken
Good point - everything which needs to fade out needs to be within #page block.
You have a great piece of coding and it should be more widely used. The only confusing thing that I noticed and it took me a while to figure out…
You never say you must have a div that wraps around the whole content of your webpage… in your caseotherwise the script init will not work as it specifically looks for ‚page‘. As shown below.
// make the page appear on load $(‚page‘).hide(); new Effect.Appear(‚page‘);
Either make a new div named ‚page‘ or add your own and change the ID reference in the Init script.
Otherwise, good work!
@Ryan I don't know – Your website is not working…
What am I doing wrong?
http:// www .ishowpro.com/Exhibitors/booth_test.aspx
>> edited by Piotr to remove 404 link from the page
Post new comment