Mootools Tutorial: Text fading effect on links
Mootools is one of the best Javascript frameworks available. It is fast to load, powerful and allow you to create stunning visual effects. In this tutorial, I’m going to show you how you can easily create an absolutely stunning fading effect on your links.
Getting started
Of course, the first thing to do is downloading the mootools framework. In this exemple, I’m using a version released last year (That you can download here) but there’s no particular reason why it shouldn’t work with other versions.
If you want to see a live demo of this effect, just have a look here and mouse ouver the links on the menu or the sidebar.
You’ll also need a separate .js file to put the script. You can embed the javascript code within the <head> and </head> html tags if you prefer, but in my opinion it is better to have the Javascript code in a separate text file.
If you’re new to Mootools you should check out this great tutorial that will teach you Mootools basics and show you an exemple of its numerous possibilities.
Integrating the framework in your HTML page
Nothing hard here. Once you created an empty file named links.js, you can integrate both the Mootools framework and this file in your html document:
<script type="text/javascript" src="mootools.js"></script> <script type="text/javascript" src="links.js"></script>
The code
We’re now ready to play! Open your links.js file and fill it with the following code:
window.addEvent('domready', function() {
var list = $$('a');
list.each(function(element) {
var fx = new Fx.Styles(element, {duration:500, wait:false});
element.addEvent('mouseenter', function(){
fx.start({
'color': '#999'
});
});
element.addEvent('mouseout', function(){
fx.start({
'color': '#000',
});
});
});Right now, when you’ll mouse over any of your links, they’ll fade from #999 to #000. Very nice, isn’t it?




15 Comments + Trackbacks
10.23.2008
It such a simple and effective tip, definitely worth implementing in any site. Thanks.
10.24.2008
Cool tips. It will make my blog looks more interesting with this. Thanks for sharing.
Wei Liang
10.25.2008
Thanks, guys!
10.27.2008
it is fun adding these to my page. this will add more interest and effects. thanks!
11.13.2008
it looks great on firefox.
but isn’t it working on ie7?
11.18.2008
@mt85 – mootools is a standard library. it works in the worst of all browsers (read ie6) . so it should work in the second worst too (read ie7)
11.21.2008
doesnt work in ie7.
so its useless, ie. no point.
11.29.2008
It also should work on iE, I use a likewise script. Maybe remove , behind ‘color’: ‘#000′
12.4.2008
I really enjoy Mootools framework.
Although Jquery is right up there too
12.6.2008
Working fine here with Firefox.
12.7.2008
Great effect. Slim code to, so you can really spice up a site without weighing it down.
2.27.2009
I can use this one for some of my social sites. Thanks.!
3.25.2009
i use jquery for ‘Text fading effect on links’ in blogspot. thanks for sharing.