MooTools 1.2 for The Non Programmer - Part 4
This will be the culmination of the four part series on MooTools for non programmers. In this installment we will take all that we learned in the previous parts and put it together to make a flash menu system.
First things first. We need some HTML to make our menu. This is just a basic unorded list. We’ve all used them thousands of times before so not much explanation needed here.
<ol id="moveMeList">
<li>First</li>
<li>Second</li>
<li>Third</li>
<li>Fourth</li>
<li>Fifth</li>
</ol>
Pretty simple so far. Out list is pretty ugly at this point so we are going to add some style to it. Again, this will just be some really basic CSS applied to our list.
#moveMeList li { display: block; margin: 0; padding: 4px; width: 120px; background: #f90; color: #fff; cursor: pointer; list-style-type:none; }
We’ve got our HTML and CSS all fleshed out so all thats left if the wonderful javascript. MooTools makes this almost too easy. We are going to animate the color of the text, background color, height and margin of our list items when you mouseover them. This all adds up to a pretty neat effect as illustrated below.
window.addEvent('domready', function() { // Grab all of our list items var ListEles = $$('#moveMeList li'); // Loop through our list items ListEles.each(function(item, index) { // Set our morph defaults item.get('morph', { duration: 500, transition: 'bounce:out' }) // Add a mouseeneter event listener to trigger our effect item.addEvent('mouseenter', function(e) { $(e.target).morph({ marginLeft: 20, color: '#333', backgroundColor: '#ff3', height: 35 }); }); // Add a mouseleave event listener to trigger our effect item.addEvent('mouseleave', function(e) { $(e.target).morph({ marginLeft: 0, color: '#fff', backgroundColor: '#f90', height: 20 }); }); }); });
- First
- Second
- Third
- Fourth
- Fifth











March 19th, 2008 at 11:34 pm
nice tutorial given by you good i appreiciate to your work
March 19th, 2008 at 11:42 pm
Thank you for these wonderful tuts.
Very helpful.
June 27th, 2008 at 3:58 pm
You could actually simplify the last example and use addEvents({obj}). Other than that, kudos for the series – good to know people still think about the non-devs!
August 5th, 2008 at 7:49 am
Hey. I think this type of thing is really great. Thanks for doing this, seriously.
December 30th, 2008 at 7:45 pm
Exactly what I needed. Thanks for taking the time, great work.