MooTools Accordion: Mouseover Style
Everyone loves the MooTools Accordion plugin but I get a lot of requests from readers asking me how to make each accordion item open when the user hovers over the item instead of making the user click. You have two options: hack the original plugin or simply fire the click event when the mouse enters the toggler. My vote is for option two -- here's how to do it.
The MooTools JavaScript
//make the accordion
var accordion = new Accordion($$('.toggler'),$$('.element'), {
opacity: 0,
onActive: function(toggler) { toggler.setStyle('color', '#f30'); },
onBackground: function(toggler) { toggler.setStyle('color', '#000'); }
});
//make it open on hover
$$('.toggler').addEvent('mouseenter', function() { this.fireEvent('click'); });
As easy as it gets -- simply fire the click event when the user's mouse enters the toggler!
If you aren't familiar with the MooTools Accordion, click here.
MooTools has always gotten a bit of grief for not inherently using and standardizing namespaced-based JavaScript classes like the Dojo Toolkit does. Many developers create their classes as globals which is generally frowned up. I mostly disagree with that stance, but each to their own. In any event...
If you follow me on Twitter, you know that I've been working on a super top secret mobile application using Appcelerator Titanium. The experience has been great: using JavaScript to create easy to write, easy to test, native mobile apps has been fun. My...
Mozilla's Christian Heilmann is an evangelist that knows how to walk the walk as well as talk the talk. You'll often see him creating sweet demos on his blog or the awesome Mozilla Hacks blog. One of my favorite pieces...
Did you know you can triple-heart things on CodePen? We’ve had that little not-so-hidden feature forever. You can click that little heart button on any Pen (or Project, Collection, or Post) on CodePen to show the creator a little love, but you can click it again...
Thanks David.
I was just contemplating the mooTools accordian for one of my projects at hand.
You’ve out-slicked yourself with this offering. Thanks for this post.
Michael
Thanks, David.
This sure is useful :)
I have been trying to get this to work for weeks now!
When I finally typed in the magic right text to Google up this page – it worked in seconds!
Many thanks
I wish it had been easier to find though, I have ben on this site for ages and missed it…
..perhaps it wasn’t there yet though!
Brilliant.. Phew.
now I have the next problem to fix!
Hey there!
i’ve just got my head around mootools (i’m a php developer, not a miracle worker, jim) and i was wondering if anyone had tried tinkering with the transition/tween fx to get the bounce effect on the open/close tabs.
also if anyone could develop a real-life ctl+z so i can undo the above obscure star trek reference, that’d be great.
kthxbai
Thanks a lot !!
I was working for a few days on this accordion without finding any solution !
Now it’s done !
Thanks again =)
hello david !
how can i do mootools accordion for style.
my code used Accordion.
don’t use fx.accordion.
Nice trick, I was about to hack the source code when I ran across this. Thanks.
Thanks for the tip. Any way of making it close automatically once the mouse moves away from the toggler?
I figured it out. It’s not a js issue, it was a css issue. For those who want to know: I just forgot to make the ‘a class’ names truly unique. For example, by having more than one ‘class=”subpg_c” it highlight all these ‘li’ tags in 3 places at once. Sorry for the long post. I thought the code might show up in a separate window rather than in the post. ;) keep up the great site!
Thanks! Not being a programmer your tutorials have helped me use mootools and add excitement to my Web site. Is there a way to set the height. I’m doing something similar to what Apple did with scriptaculous. Thanks again, you’ve been a great help.
Dave
Hy!
Is it possible to close a tab after the mouse leaves?
Sorry for this stupid question, but i am absolutly new with this stuff!
Thanks for yor help!
I had one heck of a time getting the accordion to work where if you click it, it opens, if you click it again, it closes, if your mouse leaves the element, it closes.
Thank you for the mouseover code on the accordian. I feel this is slightly easier and more intuitive than the click for the general public to use on the website. This has saved me a huge amount of work and will improve the look of the site. Wish I could have written it!
Good work on that
Hi!
I am trying to make mootools good working with IE using you’re example for first…
but the result is http://www.voilagesdesign.fr/test
I use the latest realease of mootools but I’d try first with 1.2 and the result is the same…
any idea?
thanks for your website david, it is very enriching!
Perhaps you should add a notice that there is a accordion option called “trigger” which should do exactly what is done with your workaround. Sadly mootools implemented options which doesnt take effect.
The more im working with mootools the more i miss jQuery. Easier to use and more docs / demos / plugins.
yep, the “hover” event is called “mouseover” ;)
i couldn’t find it even in mootools. You’re the man, thank’s a lot!!!
It’s wonderful the trick but i have a question, how can i link it in an iframe?
I have my accordion in a main html and i tried this: but doesn’t work.
I would appreciate it if somebody helps me.
Sorry, it get the code. I mean tried this:
[code][/code] but doesn’t work.
:s again get the code i really mean: a href=”europa0.html” target=”catalogos” with the
awesome work , but .. can u give the script some option for bounce slide ? i.ve seen that this is posible , but im noob in mootools :P . pretty tnx , waiting for your reply .
transition: Fx.Transitions.Bounce.easeOut,
this is the question :P … for me worked clear !
Hey there.
I use the mootools accordion for my website. But i just want to add a simple property. I’d like to have an accordion that opens 1 or 2 seconds after opens the website. How do i realize that? I am not familiar with Javascript, so need help!
Greets.
Very beatiful plugin thanks
Cool site, i have bookmarked it for future reference
was easy to implement. great plugin.
but.. I’m having trouble with .elements top and bottom borders. I can’t get them to display. The left and right borders show fine. Any advice?
Looks great, does anyone know how to have it automatically close on mouse out? I’ll pay for someone to change the code so it closes on mouse out?
I have the same question.