Skip to content

Instantly share code, notes, and snippets.

@walterdavis
Created September 15, 2012 22:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save walterdavis/3730215 to your computer and use it in GitHub Desktop.
Save walterdavis/3730215 to your computer and use it in GitHub Desktop.
//gather all the tooltips into an array and hide them
var tips = $$('.tooltip').invoke('hide');
//gather all the triggers into another array, and loop over them
var triggers = $$('.trigger').each(function(elm, idx){
//link each tip to its trigger, using its position in the source order as the key
elm.tip = tips[idx];
//watch each trigger for a mouseover
elm.observe('mouseenter', function(evt){
//remove the "hover" style from all triggers
triggers.invoke('removeClassName','hover');
//add it to this one that you're hovering over
this.addClassName('hover');
//hide all the tips
tips.invoke('hide');
//show the one related to this trigger
this.tip.show();
//now do the same thing in reverse for a mouseout
}).observe('mouseleave', function(evt){
//hide all the tips
tips.invoke('hide');
//remove the hover style from this one
this.removeClassName('hover');
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment