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.
- First
- Second
- Third
- Fourth
- Fifth
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
nice tutorial given by you good i appreiciate to your work
Thank you for these wonderful tuts.
Very helpful.
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!
Hey. I think this type of thing is really great. Thanks for doing this, seriously.
Exactly what I needed. Thanks for taking the time, great work.
Hey, i’ve never used JS for other than history back and alert and now i allready feel pro :p hehe, know the basics and the advanced of PHP/MySQL and some CSS and HTML but never managed to start with JS, but after this tutorial i got a hope back so thanks for getting me to like useing JS
Thanks again
Norclick, Glad we could help get an interest in JS going for you. MooTools makes it MUCH better.
Mike