Create a Simple, Powerful Product Highlighter with MooTools
In Javascript / AJAX, Site Builds by Jeremy PeckThe Demo
So here's what we're building, it's a clever rollover mechanism that works really well as a product highlighter.

Why MooTools?
I know what you're thinking... What could MooTools possibly have to offer that might cause me to break off my long-standing relationship with jQuery—Or Prototype and Scriptaculous for that matter!
One of the biggest problems I've ran into with using jQuery in the past, is the fact that so many of their plugins are created and developed independently—which MEANS, you're placing your trust in a stranger to be actively updating their plugin as the jQuery library continues to release newer and newer versions as well. When this fails (and often times it does) you'll find yourself searching for the proper version of the core library that'll allow your script to function correctly!
Maybe Prototype and its well known partner in crime, Scriptaculous, are more your style. In this particular case you'll be deprived of your right of modularity, and you're forced to include two beefy sized libraries on all of your pages—or in some cases a plugin file as well!
So if MooTools is so great then... why isn't it used more? Why aren't there gazillions of tutorials and books on every library shelf?! There's a handful of reasons:
- MooTools is geared more towards the intermediate to advanced scripter.
- You won't find collections of cut and paste plugins that allow for immediate implementation.
- MooTools users are (for whatever reason) associated with having an elitest disposition.
However, you will find ample tools for working with more unique areas of scripting, like JSON file parsing, cookies, and flash embedding to name a few. Also, a convenient download page that lets you choose exactly what you need for your project so you can ensure the smallest file size possible.

Step 1 - Get MooTools!
Head over to the MooTools Core Builder page! For this particular project, you'll want to select Fx.Morph, Element.Event, DomReady, and Selectors and hit "Download" using YUI Compressor. All dependencies are automatically chosen for you. Be mindful, as certain browsers will add a '.txt' extension to a javascript file for your protection. This will obviously need to be removed, and feel free to trim off some of the beefy characters in the file name.
Step 2 - Attach MooTools to your HTML document
Create the HTML document you'll be using for this project, and attach the MooTools library. My page head looks something like this:
<head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Mootools - Product Highlights!</title> <script src="mootools.js" type="text/javascript"></script> ... </head>
Step 3 - Lay down your CSS and HTML
Take a look at the following styles and HTML to see how I've laid out the page.
CSS code:
<style type="text/css" media="screen">
body {
margin: 0;
padding: 0;
background: #1a1613 url(images/bg_tutBody.gif) repeat-x;
}
img { border: 0; }
#siteWrap { /* The wrapper for my page icons and bubbles */
margin: 287px auto 0 auto;
width: 642px;
height: 345px;
position: relative;
background: transparent url(images/bg_pageWrap.jpg) no-repeat top left;
}
#pageWrap { /* Wrapper for my page icons */
position: absolute;
z-index: 5;
top: 138px;
left: 134px;
}
/* Page specific styles */
#psdPage {
margin-right: 19px;
float: left;
cursor: pointer;
}
#netPage {
margin-right: 20px;
float: left;
cursor: pointer;
}
#audioPage {
float: left;
cursor: pointer;
}
#bubbleWrap { /* Wrapper for my bubbles */
position: absolute;
z-index: 10;
left: 158px;
top: 30px;
}
.bubble {
position: absolute;
}
</style>
HTML code:
<div id="siteWrap"> <div id="bubbleWrap" style="visibility: hidden;"> <div class="bubble"><img src="images/bubble_PSD.jpg" alt="PSDTUTS" /></div> <div class="bubble"><img src="images/bubble_NET.jpg" alt="NETTUTS" /></div> <div class="bubble"><img src="images/bubble_AUDIO.jpg" alt="AUDIOTUTS" /></div> </div> <div id="pageWrap"> <div class="page" id="psdPage"><a href="#"><img src="images/page_PSD.jpg" alt="PSDTUTS" /></a></div> <div class="page" id="netPage"><a href="#"><img src="images/page_NET.jpg" alt="NETTUTS" /></a></div> <div class="page" id="audioPage"><a href="#"><img src="images/page_AUDIO.jpg" alt="AUDIOTUTS" /></a></div> </div> </div>
Notice how I have the HTML laid out. I will not be using ID's to select any of the page or bubble elements, and instead creating arrays of all elements containing the two classes, which will allow for this script to scale regardless of how many items you choose to highlight! All bubbles and pages are contained in a wrapper which is absolutely positioned within the site wrapper (which contains our background where all of this is sitting on top of).
Step 4 - Add your javascript
We'll start by creating a wrapper function for our javascript code which places an event listener on the window object, firing once the DOM is loaded and ready. This is important because we need our script to immediately begin altering the DOM once its available.
If we DON'T use this wrapper function, it's quite likely you'll get errors claiming that certain elements don't exist. Another option could be to place the embedded javascript at the end of the document body. However, if you decide to attach the script externally, you'll run into this problem once again, so it's a good habit to get into now!
Another option for 'domready' is to use 'load' which will fire once the page (images included) is completely loaded. We don't want this for this particular project because it means images (such as our bubbles) might intitally flash on the screen before being hidden by our script.
One other important thing to note—if you DO decide to link this script from an external '.js' file, you'll want to ensure you link it AFTER you've linked the MooTools library in the document head.
window.addEvent('domready', function() {
...
});
Next we start by creating the arrays for both our page and bubble elements and set some initial in-line styles.
window.addEvent('domready', function() {
// Create variables (in this case two arrays) representing our bubbles and pages
var myPages = $$('.page');
var myBubbles = $$('.bubble');
// Set bubbles opacity to zero so they're hidden initially
// and toggle visibility on for their container back on
myBubbles.setStyle('opacity', 0);
$('bubbleWrap').setStyle('visibility','visible')
});
Lastly, we'll attach event listeners to the page icons to fire morph effects on their corresponding bubbles. Note that the order of the bubbles as laid out in the HTML is the SAME order of the page icons. This is important!
window.addEvent('domready', function() {
// Create variables (in this case two arrays) representing our bubbles and pages
var myPages = $$('.page');
var myBubbles = $$('.bubble');
// Set bubbles opacity to zero so they're hidden initially
// and toggle visibility on for their container back on
myBubbles.setStyle('opacity', 0);
$('bubbleWrap').setStyle('visibility','visible')
// Add our events to the pages
myPages.each(function(el, i) {
/* Here we change the default 'link' property to 'cancel' for our morph effects, which
ensures effects are interrupted when the mouse is leaving and entering
to immediately begin the morph effect being called */
el.set('morph', {link : 'cancel'});
el.addEvents({
'mouseenter': function() {
myBubbles[i].morph({
'opacity' : 1,
'margin-top' : '-15px'
});
},
'mouseleave' : function() {
myBubbles[i].morph({
'opacity' : 0,
'margin-top' : 0
});
}
});
});
});
You'll notice that we're attaching a function using the each() method to all of the elements of the 'myPages' array. And for each function we pass in 'el' which represents the page element, and 'i' which is an integer representing the placement of that page element within its array. We use the 'i' variable for calling the morph effect on the appropriate and corresponding bubble element within the 'myBubbles' array.
And thats it! Pretty painless wasn't it? Be sure to view the working demo, and also bookmark the MooTools Docs page and MooTools Download page for future reference! I hope this tutorial was helpful, and I look forward to putting together something a bit more advanced in the near future using the power of MooTools classes!
Comments
Leave a CommentAdd a Comment














Abethebabe
July 13th, 2008
Thats a pretty cool effect!
TS
July 13th, 2008
Elitist attitude is pretty spot on from my experience. I love moo tools, and I use it almost as much as jQuery; but their recent update, including a complete site and doc overhaul, made the new version much more difficult to learn for a non-programmer.(I’m a designer who has to do his own production work for the most part.) The blog entries were not very helpful in explaining the changes, and the community was cold at best on the subject, referring me to the official blog. That being said, I hope you do some more with Moo Tools, especially for us non-programmer JS users who are hacking our way through it all.
RM
July 13th, 2008
TS, I recommend you to start learning mootools 1.2 from David Walsh’s blog. Trust me, mootools 1.2 is even easier to use…check it out and give me a feedback…
The cow rocks!
Andrei Constantin
July 13th, 2008
This is really neat. I will deffinately give it a try
Danny
July 13th, 2008
Hey this is pretty cool, very useful
Tommy M
July 13th, 2008
I like it! Thanks for giving MooTools a spotlight as well. Probably the most underrated of all the major libraries.
Bruce Alrighty
July 13th, 2008
It is a bit like Coda Bubbles but with Mootools.
Nice Job Jeremy.
Furto
July 13th, 2008
Such a great tutorial, so short yet such a great result. Definitely want to see more mootools!
webdemar
July 14th, 2008
Definitely useful effect! I’ll use it in one of my future projects. Thanks and keep it up!
Ben Griffiths
July 14th, 2008
I really really like this effect, going to have to try it out
thanks 
X-OR
July 14th, 2008
Nice effect !!!, for me mootools is the best library !
Hein Maas
July 14th, 2008
Hi,
Great effect, only one question. Is it easy to ad it to a wordpress blog if so could you explain me how to do that.
Best Regards.
Andrew
July 14th, 2008
@TS - You’re right, the new version is much more difficult… and it doesn’t seem like there are that many resources to look through. I’ve implemented various effects on my site (using the previous version 1.11 I think) and it wasn’t that hard… however, with the new MooTools version things definitely got harder.
–
Great tutorial… gonna try it as soon as I can.
Bilal
July 14th, 2008
Hey..its great
Thnx a lot..
ali
July 14th, 2008
nettuts is the best tuts site.
ill see what i can do with this effect later on, thanks!
Clemson
July 14th, 2008
Very Nice Tut. I guess I didn’t consider MooTools to be that hard to use, then again I also don’t consider myself to be an advanced scripter either. MooTools has some pretty cool effects that I haven’t seen anywhere, or at least in a modular form (like you said).
Andrew
July 14th, 2008
Nice tutorial, slick effect.
Benjamin David
July 14th, 2008
Hi and thanks a lot for this tutorial. I’m happy you sometimes put Mootools tutos instead of jQuery.
Juzz
July 14th, 2008
If it possible to modified that tutorial for navigation system? I mean, anchor element would come visible and user can click it. Now the come up -div is going hidden if user remove mouse position. Nah, hard to explain. Newbie with MooTools.
Cansado
July 14th, 2008
Great tutorial, simple, quickly and effective! Like always in TUTS great design valued added so we can learn visual possibilities.
Im with TS! Keep programing simple for designers detailing all the process starting at 0.
Drupal Museum
July 14th, 2008
Cool effect. I plan on using this in a project I’m working on now.
ben
July 14th, 2008
very nice effect
Jeremy
July 14th, 2008
@TS - You’re right, MooTools just recently released the official version 1.2 in the last few months, and their site still has a lot of catching up to do…
The demos section is still nowhere near the quality that the previous version was. If you DO check out their new demos page, I’ll give you a pointer - if you have FireBug installed for FireFox (and you should!), pop it open and go to the “Script” tab. On each demo page, they’ve attached the javascript for that particular demo in a .js file called “demo.js.” So use the script tab to select the demo.js file, they’re all very well commented. (this is still a bit of an inconvenience compared to the functionality of their old demo pages)
I’d be interested to hear how helpful their IRC channel is, I’ve yet to check it out for myself.
Timothy Long
July 14th, 2008
why mootools? not a question that even needs dignification.
this is a beautiful effect. i’ll definitely be putting this to good use.
webz
July 14th, 2008
such a great effect, using mootools, i love working the js library.. but i guess this can be done easily usin jquery.. but don’t have any idea how to work it.. ^_^
Taylor Satula
July 14th, 2008
Gotta find something to use this for
Gonzalo
July 14th, 2008
Wow, nice effect, I HAVE to use this somewhere!! Thanks
ben
July 14th, 2008
This looks great
ahnShev
July 14th, 2008
nice effect
Addison Kowalski
July 14th, 2008
So rad! I will be using this very shortly on an upcoming project! More MOOTOOLS tuts!
rob
July 14th, 2008
thank you, lovely one!
Karl Hardisty
July 14th, 2008
Another excellent tutorial - thank you.
We’re often cautious about including unnecessary elements in our sites, however on occasion something like this is needed, and the tutorial makes it painless to implement such tools.
Mike Smith - Blog Theme Machine
July 14th, 2008
I agree with TS, mootools tutorials are definitely something I will read 100 times over. This tutorial is great, as is your entire site. Keep the awesome tutorials coming; they are gold to someone like me
mamjed
July 14th, 2008
can i load the mootools from the inside of my page. inside the body tags?
Jeremy Peck
July 14th, 2008
@mamjed - You’ll have to link the library within the tags, embedding an entire library on a page would probably not be a very wise idea =P
Mike
July 14th, 2008
It’s a nice effect but this tutorial isn’t very detailed. Judging from the comments, a lot of the people that come to this site are beginners and will have no idea about syntax and functions and other programming ideas and concepts.
Just a little something to keep in mind.
Zaigham
July 15th, 2008
Thats pretty cool.
Thanks man!
Joefrey Mahusay
July 15th, 2008
Really cool! Thanks
Shane
July 15th, 2008
@Bruce - exactly right - I think most of us will have first seen the effect here: http://www.panic.com/coda (hover over download in main navigation area).
It’s good to have exposure of several javascript libraries, but for me, it’s jQuery all the way
Thanks for posting.
Shawin
July 15th, 2008
Awesome! Thanks. Been looking for a nice tutorial for this since panic’s coda site went up.
w1sh
July 15th, 2008
Seems overly complicated. Couldn’t you simply make a rollover with animated gif or something?
eh. I need to learn something new anyway.
Shannon
July 15th, 2008
I’ve been trying to figure out why I should learn mootools because so far it just seems it’s harder to pick up and learn than jquery. I think more resources, that are easier for designers to understand would certainly help. This is a big step in that direction, thanks!
Matt Radel
July 15th, 2008
Nice one! I’d be interested to know if there’s a way to position the balloon directly over each of the items.
stock
July 15th, 2008
I love mootools!! this is my favorite framework, very clean, very neat, it’s just awesome.
Stefan
July 15th, 2008
Finally, some moo!
Jeremy Peck
July 15th, 2008
@Matt Radel - There’s a few ways you could do this using the current script by just editing some of the styles. It would also be pretty easy using some of the other mootools methods to dynamically place bubbles in a position according to their toggler.
Try removing the #bubbleWrap div from around the bubbles, and give the bubbles unique ID’s that position them absolutely where you want them through your stylesheet. You might have to use in-line styles to set the visibility to hidden for the bubbles initially if you’re seeing them blip on the screen and then disappear suddenly…
If you remove the wrapper div #bubbleWrap, make sure to also remove line 10 in the js:
$(’bubbleWrap’).setStyle(’visibility’,'visible’)
or you could get an error.
Working on spiffy MooTools powered RSS reader right now, to come!
peter
July 15th, 2008
Hey guys, can you make a tutorial about how to create a joomla template? Please Please Please :(((
Jacob Gube
July 15th, 2008
I don’t think you have to justify using MooTools (just like you wouldn’t have to explain using Ruby on Rails or ASP.NET as opposed to PHP) in the introduction - it’s a wonderful JavaScript library! Just like a server-side language - you pick the one that you’re more comfortable with and what your team has chosen. jQuery is definitely the most popular library out there today, great performance, decent file size, well-documented - but there’s over a hundred other libraries/frameworks to choose from. MooTools allows you to customize the framework so that you can grab only the stuff you need, which I think is pretty cool.
John Deszell
July 15th, 2008
Sweet Tut, I’ll have to try it out on a future project.
Adam
July 15th, 2008
Could you provide the source files for the graphics??? They are really cool, Please!
Thanks
Adam
Mark Abucayon
July 15th, 2008
That was cool, I like the effect of this one. thanks for sharing this. cool
Lamin Barrow
July 16th, 2008
WOW. neat effect. Thanks for for the article and for using mootools.
Dave
July 16th, 2008
Very nice and clean! it’s possible to share or send me the PSD or source file of graphic part … ? thx
Timmy
July 18th, 2008
What it need to change if I want feature which enable mouse over highlight-image and image won’t disappear if cursor is in navigation or highlight area?
Rubel
July 18th, 2008
Cool… Effect
Namelezz!
July 19th, 2008
Thanks for sharing this!
Daniel Barreto
July 20th, 2008
Hey! thanks for the article. And you are right, Mootools Rules!
Daniel
July 26th, 2008
great tutorial! very useful for the project i work on. thanks a lot.
Jo
August 1st, 2008
always wondered how that coda effect worked.
thanks alot
one question though:
your html code seems to be suffering from div-itis.
can’t you just use a ul ?
or is it needed for the javascript to work?
compleet javascript noob here
Devin
August 1st, 2008
I’ve tried this script on a brand new design and it works great for me in Internet Explorer and Firefox but other people that try to view it in Firefox cannot see it. Must be an error on my part…not sure
But this is an amazing effect!
loadmemory
August 3rd, 2008
Great work! Thanks for sharing!
madsheep
August 4th, 2008
Preaty cool efect.
Such a shame it takes two times more code with mootols than with jQuery.
Raj
August 4th, 2008
cool effect. Thanx a lot!
questionare
August 6th, 2008
I downloaded the source and made a few edits regarding photos, text etc just to play around. But Now it only shows a blank page in internet explorer/Opera and i don´t understand why. I made no big changes but it wont show up in IE. works fine in FireFox
MK Owens
August 14th, 2008
I’ve got to admit; with all of the jQuery content on NETTUTS, I was starting to wonder if I was ever going to find an “immediately useful” tutorial related to Javascript because I’ve been a Mootools user since v1.07 and much prefer its extensible nature to any of the other “big name JS frameworks.” While a lot of the JS on NETTUTS has been useful in giving me inspiration to develop my own scripts (just as valuable as an “immediately useful” tutorial, imho), I would love to see more Mootools-based tutorials, as our community needs the exposure. Most of the companies that I have worked with have loved Mootools once they were given the opportunity to play with it, but because things like this are far and few in between for the Mootools community (as compared to jQuery, Script.aculo.us/Prototype, or even non-framework based JS) it has been a tough battle at times to convince clients and employers to use it on their sites.
I’m a lot more inclined to write up a few interface tutorials to submit now that I know that some of the people on NETTUTS support Mootools, and Mootools users are allowed to enjoy recess, too.
As an aside: For all of the people who have mentioned the “elitist attitude” of Mootools users, we’re not all like that. We just don’t get asked to come out and play as often as you jQuery and S/P users. People usually refer to our love of milk as the reason, but that’s okay . . . we’re mad for milk!
Jeffrey Way
August 14th, 2008
@MK - It’s all a matter of what we receive. We simply don’t get many Mootools submissions. Please feel free to submit a tutorial if you write one up!
MK Owens
August 14th, 2008
Fair enough, Jeffrey. I’m curious what would be the most requested tutorial submissions (esp. related to Mootools, PHP/MySQL, and gen XHTML/CSS), as I don’t want to submit something that people aren’t all that interested in.
İsmail Kaya
August 15th, 2008
very useful thank you
Pi[ks]ite
August 19th, 2008
It is nice ! but…
But if you also use the MooTools More Builder, you will notice a little bug : sometimes the mouseleave event bugs.
Thus, if you use the More Builder, better is to use Fx.Elements.
Here is the javascript part to use :
var Bubbles = new Class({
options: {
onOpen: false,
onClose: $empty,
transition: Fx.Transitions.linear,
duration: 500,
open: null
},
initialize: function(elements,bubbles,options){
this.setOptions(options);
this.elements = $$(elements);
this.bubbles = $$(bubbles);
this.BubbleFx = new Fx.Elements(this.bubbles, {wait: false, duration: this.options.duration, transition: this.options.transition});
this.elements.each(function(elt,i){
elt.addEvent(’mouseenter’, function(e){
new Event(e).stop();
this.reset(i);
}.bind(this));
elt.addEvent(’mouseleave’, function(e){
new Event(e).stop();
this.reset(this.options.open);
}.bind(this));
var BubbleObj = this;
}.bind(this));
},
reset: function(num){
var BubbleObj = {};
this.elements.each(function(elt,i){
BubbleObj[i] = {’opacity’: 0, ‘margin-top’ : ‘-35px’};
}.bind(this));
if($type(num) == ‘number’){
BubbleObj[num] = {’opacity’: 1, ‘margin-top’ : ‘-85px’};
}
this.BubbleFx.start(BubbleObj);
}
});
Bubbles.implement(new Options, new Events);
window.addEvent(’domready’, function() {
// Create variables (in this case two arrays) representing our bubbles and pages
var myPages = $$(’.page’);
var myBubbles = $$(’.bubble’);
// Set bubbles opacity to zero so they’re hidden initially and toggle visibility on for their container
myBubbles.setStyle(’opacity’, 0);
$(’bubbleWrap’).setStyle(’visibility’,'visible’);
new Bubbles(myPages,myBubbles);
});
Pi[ks]ite
August 19th, 2008
[this post is to edit my previous post in order to respect values from the original code]
sorry, if you cloud change :
this.elements.each(function(elt,i){
BubbleObj[i] = {’opacity’: 0, ‘margin-top’ : ‘-35px’};
}.bind(this));
if($type(num) == ‘number’){
BubbleObj[num] = {’opacity’: 1, ‘margin-top’ : ‘-85px’};
}
by :
this.elements.each(function(elt,i){
BubbleObj[i] = {’opacity’: 0, ‘margin-top’ : 0};
}.bind(this));
if($type(num) == ‘number’){
BubbleObj[num] = {’opacity’: 1, ‘margin-top’ : ‘-15px’};
}
omrcm
August 22nd, 2008
I’m enterested avery time on this tecnology.
Windows Themes
September 5th, 2008
Wow. I really like this one. Is amazing. Thank you so much